Populate DataGrid with dynamic colums

Is it possible to populate a DataGrid from Json that contains the columns properties who is not always the same ?

1 Reply

JA Jayaraman Ayyanar Syncfusion Team March 22, 2018 10:53 AM UTC

Hi Moshab, 
 
Thanks for contacting Syncfusion support. 
 
We have checked you query. The query for the “Populate DataGrid with dynamic colums” can be achieved by using the following steps. 
 
  1. JSON data cannot be bound directly to SfDataGrid. To bind SfDataGrid with JSON data, we must deserialize the JSON data to a bindable format. You can use the open source NuGet Newtonsoft.Json to serialize and deserialize JSON objects.
  2. Xamarin.Forms have limitations in loading dynamic object (Expando object). Hence dynamic objects can be loaded only using dictionary collection. Refer the dynamic limitations for more details.
  3. JSON data can be parsed into a dictionary collection using JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(json_object).
  4. You can then convert the list of dictionary objects to an observable collection if your data source need to respond to collection changes.
  5. The List of Dictionary objects or the converted ObservableCollection can now be binded as ItemsSource of SfDataGrid.
 
We have also prepared a sample for your requirement and You can download the same from the below link: 
 
Regards, 
Jayaraman. 
 


Loader.
Up arrow icon