This is a migrated thread and some comments may be shown as answers.

How to set grid datasource object to existing grid periodically

1 Answer 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nilesh
Top achievements
Rank 1
Nilesh asked on 02 Jun 2012, 08:06 AM
I have created Kendo Grid datasource and want to set updated data object to it
for that i written following code as

//get reference of created grid
var grid = $("#admin-grid-todo").data("kendoGrid");

//to set data to referenced grid
grid.dataSource.data(
                   dataFromAjax
                );


I get dataFromAjax as String object from Ajax call so that it will gives error as ID is not defined
dataFromAjax is in format of [{ID:'1',NAME:'job1'},{ID:'2',NAME:'job2'}]

If i write hard coded dataFromAjax as
var dataFromAjax = [{ID:'1',NAME:'job1'},{ID:'2',NAME:'job2'}];
It will works fine.

I want to know is there any way to get data as object from Ajax return call

Thanks,
Nilesh Mantri

1 Answer, 1 is accepted

Sort by
0
Nilesh
Top achievements
Rank 1
answered on 02 Jun 2012, 09:53 AM
Here i got solution as
Include JSON libraries to your project

After including jars you can parse String object into json object as

JSONSerializer json_serializer = new JSONSerializer();
Object dataFromAjax = json_serializer.toJSON("{ID:'1',NAME:'job1'},{ID:'2',NAME:'job2'}");


After getting response from Ajax you can set updated data object as previous

grid.dataSource.data(
                   dataFromAjax
                );

You can download json jar files from following link
www.roseindia.net/tutorials/json/JSONLibraries.zip

Thanks,
Nilesh Mantri
Tags
Grid
Asked by
Nilesh
Top achievements
Rank 1
Answers by
Nilesh
Top achievements
Rank 1
Share this question
or