3

I have a jqGrid with 100+ rows that are displayed in Edit mode by default. I am trying to figure out a way to send all row data in one call to the server.

The problem - How to get the row data in edit mode (getRowData method returns the html)?

Once I get all the row data, I can hopefully parse them in a JSON format and send it to the server via jQuery.ajax() call.

Any help in this regard is greatly appreciated!

RRK
  • 465
  • 2
  • 7
  • 21
  • I saw Oleg's response to a similar question - ['code']$("#" + rowid + ">td:nth-child(" + (i + 1) + ")>input").val()['code']. This works. However, I have a column that is not editable for some rows, and also some columns are and so the above strategy may involve too much of hard coding. – RRK Apr 30 '13 at 21:52

1 Answers1

4

I can imagine me many ways to implement you requirements. I would describe you the simplest one. It consist from

  • saving of all editing rows. If you use inline editing mode then you need call saveRow for all editing rows. Because saveRow tests internally whether the row in editing and because the most rows (probably even all) are already in editing mode, you can just use getDataIDs to get array of ids of all rows and then call saveRow in the loop for every from returned id.
  • usage of getRowData without parameters or usage of getGridParam to get "data" option.
  • send the data to the server using jQuery.ajax.
  • the last step is optional. You can start editing mode for all the rows.

I think that the above approach is not only mostly easy implemented. It's mostly save, because it works for every editing control (inclusive custom one).

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I had started my implementation in this way but got stuck. Here is my concern with the above approach. When I loop through the array of ids and call saveRow, if there is a validation error on one of the rows e.g. required field, that row will remain in edit mode. And then when I use getRowData, I will get html content for that row. Is there a way, I can add row data to a JSON object when saveRow succeeds for each row? I tried "aftersavefunc" handler of saveRow but it gets called with rowId and true/false. – RRK Apr 30 '13 at 22:40
  • On second thought - I guess in "aftersavefunc" I can see if the row is saved successfully or not. If saved successfully, I can then use getRowData using the rowId and then add to a JSON object. I will give this a try but if you have a better implementation, let me know. – RRK Apr 30 '13 at 22:46
  • 1
    @RRK: You can easy detect validation error (the case that not all rows will be saved and still are in editing mode) by getting `"savedRow"` option (`$("#grid").jqGrid("getGridParam", "savedRow")`). The returned value is empty array if no rows are editing now. – Oleg Apr 30 '13 at 22:53
  • Thanks Oleg!! For anyone else facing a similar issue, I followed Oleg's steps but also used "aftersavefunc" handler of saveRow to collect all the successfully saved rows into an array. After all rows are processed, I check to see if there are validation errors using `$("#grid").jqGrid("getGridParam", "savedRow")`, if no validation error, then I make an AJAX call to server sending the array. – RRK May 02 '13 at 23:54