3

I'm adding some rows data to my JQGrid on client side with javascript :

var grid = jQuery("#<%= JQGridMembers.ClientID %>");
var rowKey = grid.getGridParam("selrow");
var newRow = [{ ID: memberId, FullName: memberFullName, Percent: parseInt(percent)}];
grid.addRowData(memberId, newRow);

above code works well , but How can I get all inserted rows data (in JQGrid) in code-behind?

Mohammad Dayyan
  • 21,578
  • 41
  • 164
  • 232
  • Just one remark: I would you recommend don't use `addRowData` if it is *really required* and there are no other way. The only use case is if you get new rows *along*. For example if the user clicked on "Add" button explicitly and added new data. In case if you get *many rows* and need to clear the old contain and insert new data in the grid the usage of `addRowData` would be the wrong (the slowest) way. – Oleg Mar 17 '12 at 10:42

2 Answers2

11

You can get all rows from the grid by

var myData = grid.jqGrid('getRowData');

or with respect of

var myData = grid.jqGrid('getGridParam', 'data');

The last way can be used only with local datatype or in case of loadonce: true. It returns data not only from the current page, but all data from all pages.

The getRowData method use unformatter to read the data from all cells of the grid.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • How can you get the data for only the current page if loadonce is set to true? – mrshickadance Dec 18 '14 at 14:09
  • 1
    @mrshickadance: You can first get all `id` values from the current page. You can use `getDataIDs` for example. Then you can get every data item which corresponds the rowids using `getLocalRow` method. You can push the results in an empty array for example and add `id` property to every data item. In the way you will have full information. – Oleg Dec 18 '14 at 14:15
4

Had encountered a similar problem, below is what I ended up using

var data = $("#table-id").jqGrid('getGridParam', 'data');
for (var i = 0; i < data.length; i++) {
    var f_name = data[i].FirstName;
    var l_name = data[i].LastName;
    // blah... blah..
}

Reference

Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281