We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Binding DataTables to Grids - a solution.

Thread ID:

Created:

Updated:

Platform:

Replies:

146109 Jul 20,2019 02:32 AM UTC Jul 24,2019 12:44 PM UTC Blazor 3
loading
Tags: Grid
A. Richard
Asked On July 20, 2019 02:32 AM UTC

I have a requirement to get a DataTable and display it nicely on a Grid control.  This is pretty straightforward in Blazor with <tables>, but not trivial when it comes to binding the data to a nice, structured  Grid control.

As a control that is expecting an IEnumerable collection, DataTables don't really meet the criteria for the data binding that the Grid needs.  The DataRows are composed of ItemArrays, which will not bind nicely with the DataGrid in the ways it is expecting.  After days of pushing and prodding on this problem and a number of false starts, I've discovered dynamic objects in C# are a pretty fast and easy way to solve this mess, without having to dive into a whole mess of Reflection.  Essentially, the System.Dynamic.ExpandoObject is a weird hybrid that acts like a class, but can be set using a Dictionary.  So, by taking the columns and rows and copying them to a List of these ExpandoObjects, we're able to display the data on the screen.  This isn't going to be a two-way binding scenario (although I suppose it's possible with a bit of work), but just for displaying the data within a DataTable in a nice grid control is a good start.




Attachment: code_sample_c9996fe7.zip

Renjith Singh Rajendran [Syncfusion]
Replied On July 22, 2019 01:24 PM UTC

Hi Richard, 

Thanks for contacting Syncfusion support. 

We have analyzed your query. We suspect that, you are facing difficulties in binding a DataTable to Syncfusion Grid. Based on this requirement, we have prepared a sample to bind a DataTable as DataSource for a Syncfusion Grid. We have used the same codes which you have shared with us. We are attaching the sample for your convenience, please download the sample from the link below, 
 
Note : In the above sample we have used latest nuget and script version v.17.2.0.34-beta 

If we have misunderstood your query, or you are still facing the same problem, then please get back to us with the following details for better assistance. 

  1. Share the detailed description of your complete requirement.
  2. Share the Syncfusion version details.
  3. Share the details of the problem you are facing in binding a DataTable to Grid.
  4. Share the exact scenario or proper replication procedure.
  5. Share with us a video demo showing the problem you are facing.

The provided information will help us analyze the problem, and provide you a solution as early as possible. 

Regards, 
Renjith Singh Rajendran. 


A. Richard
Replied On July 22, 2019 03:23 PM UTC

Good Morning Renjith,

Thank you for bundling my solution nicely into a full project with data and everything.  Just to give everyone a little more context, this solution is an example of late-binding the data to a SyncFusion Grid control, where the Grid control has no prior knowledge of the DataTable schema.  This can be handy when people have dynamic data that they need to display and not necessarily edit.

Richard

Vignesh Natarajan [Syncfusion]
Replied On July 24, 2019 12:44 PM UTC

Hi Richard,  

Thanks for the detailed explanation.  

We are glad to hear that you are able to achieve your requirement using our solution. 

Please get back to us if you have further queries.  

Regards, 
Vignesh Natarajan. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon