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

add new row to radgrid client datasource with javascript

1 Answer 495 Views
Grid
This is a migrated thread and some comments may be shown as answers.
wireclou
Top achievements
Rank 1
wireclou asked on 11 Aug 2014, 08:44 AM
I'm want to insert a new row directly into the client data source doing something like this:

var data = [{ "ID": 1, "Text": "Text1" }, { "ID": 2, "Text": "Text2" }];
var mtv = $find("RadGrid1").get_masterTableView();

var items = mtv.get_dataSource(); // this won't work because is null
//var items = mtv.get_dataItems(); // this is obvious way to do it, but I want to insert a json object

var newItems = items.splice(3, 0, data); // insert object

mtv.set_dataSource(items); // (item actually get's inserted into orginal items,and not newItems - bit result is same either way)
mtv.dataBind();

However:

1) The data source is null - I guess upon rendering it gets reset
2) I can add items to the 'dataItems' array, but I guess this has to be formatted as HTML.

Is it possible to add a JSON object to the data source and rebind the grid?






1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 14 Aug 2014, 07:52 AM
Hi,

I am not sure about the exact binding used by the grid but you should be able to make things work correctly with programmatic client-side binding.

In attachments you can find a sample website that I have assembled for you that illustrates a possible realization of the targeted scenario. If you run the sample and click the Insert Items button you will notice that two records are added to the grid.

Hope the sample provided is helpful.

Regards,
Angel Petrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
wireclou
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or