In the ASP.NET Core assembly there is no ToDataSourceResult extension method for DataTables
This is not a bug. There is no DataTable support for ASP.NET Core.
Just FYI in case it makes a difference: ASP.NET Core 2 targeting .NET Standard 2.0 does support DataTables
We are currently targeting .NETStandart 1.6 which does not support DataTables. If we upgrade the packages so that support for DataTables is present we will log an enhancement and implement the extension methods.
The ASP.NET Core project has been upgraded to .NET Core 2.0. We should review this item.
If we are going to log an enhancement, we should consider the request in 1158372, where model binding to a DataTable is requested for the ASP.NET Core Grid.
@model System.Data.DataTable
@(Html.Kendo().Grid(Model)....
Without this, binding a Grid in Razor Pages to a varying number of columns is very hard, if not possible.
I would very much like to see binding to DataTables implemented.
"Without this, binding a Grid in Razor Pages to a varying number of columns is very hard, if not possible."
@TsvetinaIvanova Binding to the model like demonstrated above and in this demo is possible only for the Grid for MVC and not ASP.NET Core. The reason for this is that with such binding server rendering is used and the Core grid does not have such. However in the next official release you will be able to bind the grid to a DataTable as demonstrated below.
View:
@model System.Data.DataTable
@(Html.Kendo().Grid<dynamic>()
.Name("Grid")
.Columns(columns =>
{
foreach (System.Data.DataColumn column in Model.Columns)
{
var c = columns.Bound(column.ColumnName);
}
})
.Pageable()
.Sortable()
.Editable(ed => ed.Mode(GridEditMode.PopUp))
.Filterable()
.Groupable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
foreach (System.Data.DataColumn column in Model.Columns)
{
var field = model.Field(column.ColumnName, column.DataType);
}
})
.Read(read => read.Action("Customers_Read", "Grid"))
)
)
Controller:
[Demo]
public IActionResult Index()
{
DataTable products = GetDataTable(500);
return View(products);
}
private static DataTable GetDataTable(int howMany)
{
var dataSource = new DataTable();
dataSource.Columns.Add("Field1");
dataSource.Columns.Add("Field2", typeof(int));
for (int i = 0; i < howMany; i++)
{
dataSource.Rows.Add("value" + i, i);
}
return dataSource;
}
public IActionResult Customers_Read([DataSourceRequest] DataSourceRequest request)
{
return Json(GetDataTable(500).ToDataSourceResult(request));
}
When the next official release is going to be available? dataSourceResult for DataTables is extremely important.
@christophad
This issue was resolved in R2 2018 which was released on 16 May and is available for download.
Please read the last comment by @ag-petrov above as it states some important details about the solution.
When I update the Kendo.Mvc library via nuget, the latest version that exists is 2016.2.616 and it doesn't include toDatasourceResult for DataTables
@christophad
Kendo.Mvc nuget package is not supported anymore. Here is a list of the currently provided packages:
https://docs.telerik.com/aspnet-mvc/getting-started/nuget-install#list-of-provided-packages
Most helpful comment
The ASP.NET Core project has been upgraded to .NET Core 2.0. We should review this item.
If we are going to log an enhancement, we should consider the request in 1158372, where model binding to a DataTable is requested for the ASP.NET Core Grid.
Without this, binding a Grid in Razor Pages to a varying number of columns is very hard, if not possible.