Is there way to do complete client-side javascript binding of Grid to JSON collection ?

I have client side javascript that creates/changes JSON collection.
Can I bind Grid to this JSON collection  ?
Will grid be capable to reflect changes made to JSON collection ?
Can you give me an example if so ?



2 Replies

OL Oleksandr Lysenko December 10, 2012 01:43 PM UTC

Does anybody answering in this forum ?


GS Gowri S Syncfusion Team December 13, 2012 04:19 PM UTC

Hi Oleksandr,

 

Sorry for the delay of response.

 

We can achieve your requirement by using following script lines to update the datasource with changed JSON Collection :

 

<script language="javascript" type="text/javascript">

    function addRecord(sender, args) {

        var obj = $find('Grid1').jsonModeMgr.get_dataSource();

        var newrow = obj[0];

        newrow.CustomerID = "OPOP"

        obj.splice(0, 0, newrow);

        $find('Grid1').jsonModeMgr.set_dataSource(obj);

    }

    function removeRecord(sender, args) {

        var obj = $find('Grid1').jsonModeMgr.get_dataSource();

        obj.splice(0,1);

        $find('Grid1').jsonModeMgr.set_dataSource(obj);

    }

</script>

 

<div id="addRemoveRecord">

<input type="button" name="Add a Record" value="Add a Record" onclick="addRecord()" />

<br />

<br />

<input type="button" name="Remove a Record" value="Remove a Record"" onclick="removeRecord()" />

</div>

 

Here we have added two buttons one button to add a new row "Add a Record" and another to delete the first row "Remove a Record".

 

$find('Grid1').jsonModeMgr.get_dataSource() - gets the current datasource.

 

find('Grid1').jsonModeMgr.set_dataSource(obj) - sets the datasource for the grid with current json collection.

 

We have created a sample for your convenience. The same can be downloaded from the following link :

 

EditingSample.zip

 

Please let us know if you have any other concerns.

 

Regards,

 

Gowri S.

Loader.
Up arrow icon