Reputation: 53
Is there a way to set the dataSource using a string containing the data to display in a KendoGrid. Assuming the columns in data string matches the column definitions in the grid, I've attempted the line:
var ds = new kendo.data.DataSource ({ data: dataString });
where dataString is of the format "{ column1: value1, column2: value2 }" or "[ { column1: value1, column2, value2 } ]" followed by:
$(gridId).data('kendoGrid').setDataSource(ds);
to set new grid dataSource, however this approach is not working.
I can work around this by parsing the dataString into an object then adding this object to an array & using this array as the parameter for the data attribute when defining ds.
Is there a more efficient way to assign new data to a kendoGrid using a string containing the data to display?
Upvotes: 1
Views: 6863
Reputation: 310
First convert string to JSON and after that, set grid's data source:
$('#gridId').data('kendoGrid').dataSource.data(JSON.parse(stringData));
Upvotes: 2
Reputation: 894
You may have to invoke the read method once you set your datasource:
$(gridId).data('kendoGrid').dataSource.read();
I hope this helps. Good luck.
Upvotes: 0