Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In jqGrid, can you inline edit multiple rows at once and then do a single commit?

We are using the jQuery('#grid').editRow() feature of jqGrid, that allows you to edit fields in a row inline.

Does jqGrid support inline editing of multiple rows at once, where I can make changes on multiple rows and then submit all at once?

We are trying to avoid having to make changes to each row one by one and do a separate "round trip" to the server to commit each time, for cases were we want to bulk edit a number of fields for a number of records and have a single "commit".

like image 564
leora Avatar asked May 09 '11 21:05

leora


3 Answers

Inline editing of multiple rows is not implemented by jqGrid. You can use local editing and post all the changes to the server manually, but you will have to implement the submit of all changes yourself.

I personally would not implement such behavior in my projects. The reason is that I think that the web site should always support concurrency (optimistic concurrency have the most sense). In the case if one person try to submit the changes to the server, the server can answer with the concurrency error: some other person have already modified the data. In the case the grid data should be refreshed and the editing of row should be repeated. I see problems with implementing of editing of multiple rows in case of the usage of optimistic concurrency. How would the error messages look like? If many rows are changed how the error message should look like? What should the user do in case of error? Should he/she repeat the full changing of the data? Where are the benefit from the users point of view?

The submitting of the editing of one row was almost immediately in all jqGrid implementations which I had. So I see no need to do multiple rows at once in the projects. Disadvantages for the user in case of concurrency errors are larger as advantages from "round trip" reduction. Because of very good connection to the server the sending of the data is not a problem in environments of my customers.

like image 148
Oleg Avatar answered Nov 02 '22 02:11

Oleg


Inline editing of multiple rows is not possible in original JQGrid implementation. What the original implementation does is, every row which you edit and lose focus will be submitted.

Instead, create a custom implementation like this: 1. Override(Extend) the existing grid.inline.js and write your own edit rows and save rows. 2. In the edit rows function, configure in such a way as to add the dirty rows (edited) to be collected separately. 3. In the save rows function, you can submit only the dirty rows to the server.

And for preventing the concurrent updation of same data, you can have version control mechanism in either of the following ways: 1. Have a version field (hidden) for all the rows. When a row becomes dirty, increment the version field. 2. When submitting the rows, check for the version number existing and the new one. If there is a mismatch, intimate to the user/ update the existing. (This, you can implement quite easily)

That's it! Hope that was useful! :-)

like image 22
Satish Kumar Avatar answered Nov 02 '22 03:11

Satish Kumar


I don't know very much jqGrid, however I made this simple test (I might be missing something):

  1. Go to jqGrid demo page http://www.trirand.com/blog/jqgrid/jqgrid.html
  2. Load Road editing / Basic example page.
  3. Run this code manually:

    jQuery("#rowed1").jqGrid('editRow', '11');
    jQuery("#rowed1").jqGrid('editRow', '12');
    jQuery("#rowed1").jqGrid('editRow', '13')
    
  4. Edit the three rows

  5. Run this code manually:

    jQuery("#rowed1").jqGrid('saveRow', '11');
    jQuery("#rowed1").jqGrid('saveRow', '12');
    jQuery("#rowed1").jqGrid('saveRow', '13');
    

Of course the url parameter is required and I think you could use the callback option to gather all the edited rows.

Hope this helps

like image 1
marcosfromero Avatar answered Nov 02 '22 02:11

marcosfromero