Grid bounds to DataTable

1 Answer 70 Views
Grid
Martin
Top achievements
Rank 1
Martin asked on 28 Jun 2022, 02:35 PM

In Kendo UI for ASP.Net MVC, you could bind a grid directly to a DataTable, as in

@Html.Kendo().Grid(MyDataTable)...

where MyDataTable is a DataTable object populated with data. 

However, using the ASP.Net Core kendo libraries, there is no support for this.

Why not? Are Telerik planning to add this?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 01 Jul 2022, 07:24 AM

Hi Martin,

Binding to a DataTable is also supported in ASP.NET Core. We have a dedicated article explaining how to achieve the desired result and it also point to a repository with an example:

Bind a DataTable to Telerik UI for ASP.NET Grid

Regards,
Aleksandar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Martin
Top achievements
Rank 1
commented on 01 Jul 2022, 11:27 AM

But those examples use Ajax to read the actual data. 

I wanted to pass the actual data directly from the view model to the grid builder using Html.Kendo().Grid(Model.DataTableData)

In .Net4.x, there was an overload on the Grid() method thot took a DataTable parameter. This seems to he disappeared in the .Net Core version.

 

Aleksandar
Telerik team
commented on 06 Jul 2022, 08:43 AM

indeed the example uses Ajax to read the data. Using local binding with DataTables is only supported in the Telerik UI for ASP.NET MVC, but not in Telerik UI for aSP.NET Core. In Core you'll have to use the approach with the Ajax request that you provided in the first message. I can suggest reviewing this forum post where this has been discussed in detail. The reason is that the UI for ASP.NET Core Grid does not have server rendering, that is used with UI for ASP.NET MVC to render local data.
Martin
Top achievements
Rank 1
commented on 06 Jul 2022, 09:46 AM

But in Asp.Net Core, it works perfectly binding to an IEnumerable as local data, as in

@html.Kendo().Grid<Modelclass>( Model.ListOfModelClass)...

No Ajax calls are required to do this. The grid is actually rendered client-side, with the data being passed in the http response as json. 

I don't understand why this can't be done in the same way with a DataTable.

Martin
Top achievements
Rank 1
commented on 06 Jul 2022, 09:49 AM

In fact, I wrote an extension method for DataTable that converts the data into a IEnumerable<dynamic> and that works perfectly!

 Html.Kendo().Grid<dynamic>(Model.DataTable.ForKendoGrid())

 

 

Mihaela
Telerik team
commented on 11 Jul 2022, 07:36 AM

Hi Martin,

The ASP.NET Core framework has a bit different mechanics compared to the ASP.NET MVC. In the Core framework, the server binding is not available. That is why the Grid DataSource configuration does not support the server binding as in MVC.

Even though it is possible to pass the Model to the View as a collection and the Grid can accept it in its constructor, this would be the equivalent for local data binding:

https://docs.telerik.com/aspnet-core/html-helpers/data-management/grid/binding/local

 

Tags
Grid
Asked by
Martin
Top achievements
Rank 1
Answers by
Aleksandar
Telerik team
Share this question
or