Retrieving contents of the grid

2019-02-27 15:47发布

问题:

I am using jqGrid to display values on the client side. Initially the grid is empty and the user enters the data inline. According to the requirement, I need to submit the data once the user submits the form.

I intend to, just prior to submitting the form, format contents so that I can store the user entered details in the database. Is their any way I can get a grid data in the form of JSON?

Currently I am doing the same in the following way:

var ids = $(gridId).jqGrid('getDataIDs');
for ( var i =1; i <=ids.length; i++) {
        var id = ids[i];
        rowData = $("#"+grid).jqGrid('getRowData',id);          
    }
 //add rowData to some global object and inturn to some hidden field and sending it the server.

Is there any other way to do the same?

回答1:

I would recommend you to use

var gridData=$("#list").jqGrid('getGridParam','data');

to get full data from the grid. After you have all the data in one JavaScript object gridData you can modify it in the way which you need prior to submitting to the server.



标签: jqgrid