1

I am using a JQGrid. Based on a condition of a cell value(i.e "Stabilized" in my case) I need to update another cell of the same row. updated value should store in backend db also. I am using cell Formatter to achieve this. But I am not able to call "setRowData" in JQGrid as other parameters not able to extract rowObject parameter in Formatter method. Any suggestion is highly appreciated.

colModel: [
            { name: 'srno', index: 'srno', align: 'center', width: 60, editable: true,key:true},
            { name: 'dev_id', index: 'dev_id', align: 'center', width: 80, editable: true},
            { name: 'cmd', index: 'cmd', align: 'center', width: 280, sortable: false, editable: true },
            { name: 'dstatus', index: 'dstatus', align: 'center', width: 100, sortable: false, editable: false,formatter: deviceFormatter}
           ]  

function deviceFormatter(cellvalue, options, rowObject) {  
      if( cellvalue == "Stabilized"){
          rowObject[2] = "Some Updated Value";
        //Save the modified cell value to Grid
        // $('#jqg_test').jqGrid('setRowData', rowid, rowData);
      }
 }
Anand
  • 823
  • 1
  • 10
  • 19
  • Which **version** of jqGrid you use (can use) and from which **fork** of jqGrid ([free jqGrid](https://github.com/free-jqgrid/jqGrid), commercial [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or an old jqGrid in version <=4.7)? Which `datatype` you use and how you fill the grid with data? Do you use `loadonce: true` option? In general, custom formatter is not for *changing* the data (`rowObject[2] = ...;`), but for displaying previously filled data as HTML fragment. Could you provide an example of test data and to describe what you want to display? – Oleg Oct 06 '17 at 16:15
  • @Oleg I am using free-jqgrid/4.13.3, loadonce: false, url: 'gridtest_json.jsp', gridtest_json.jsp will call a JSON to read read from DB and bind it with JQGrid. My requirement if dstatus column is "Stabilized" then update the cmd column value to "Some String". Runtime dstatus value will be updated in db which will reflect in grid once grid is refreshed. – Anand Oct 09 '17 at 05:12
  • Could you include an example of JSON data returned from the server? It's enough to include the data 1-2 rows. If you load JSON data directly from the server then you can use `beforeProcessing` to modify the data returned from the server *before* the data will be processed and displayed. I can't include more details without having test JSON data. I'd recommend you additionally don't use old versions of free jqGrid and upgrade to the current one: 4.15.1. It's independent from your main problem. – Oleg Oct 09 '17 at 05:33
  • @Oleg, I have achieve this by doing changes in serverside. Anyways Thanks for your help and support always. – Anand Oct 09 '17 at 06:59
  • You are welcome! The idea of the usage of `beforeProcessing` you could see for example [here](https://stackoverflow.com/a/9855764/315935) – Oleg Oct 09 '17 at 07:08

0 Answers0