How to update data value in jqgrid

I am trying to update a cell in jqgrid forever after loading. I know I can use setCell , but this only updates the value for this page. If I return to the page, if I do not explicitly execute another setCell for the cell, the old value is displayed. I also tried setRowData, but it seems to do the same. I am using loadonce since my approach is 1) loading data. 2) change of several data values ​​based on some criteria. 3) display of changed values. As I use loadonce , there should be no way to constantly change the cell in this session?

UPDATE:

Introducing my code that does not give an error, but does not iterate over all the data:

 var set = 0; .... gridComplete: function(data){ setData(); }, .... beforeRefresh: function(data){ set = 0; }, .... function setData(){ if(set == 1) return; ... //create hash up here var dataArray = jQuery("#grid").jqGrid('getGridParam', 'data'); var j = 1; for (var rows in dataArray) { var key = dataArray[rows].name; dataArray[rows].level = hashTable[key]; j++; } alert(j); } 

This is not a cyclic movement over all elements of the array that are locally loaded. For example, if the page size is 30, alert(j) returns 30, regardless of how many places I loaded locally. However, if I update the graph, j is the correct number. Why is the behavior of getGridParam different in each case?

+14
jquery jqgrid
Feb 04 '12 at 22:27
source share
3 answers

If you use loadonce: true , you should know where the local data will be stored by jqGrid. jqGrid has two options: data and _index . data is an array of elements, where each element has a name property as the name property of the columns from colModel . If you need to find an element by id (rowid), you can use _index[rowid] for the element using rowid in the data array. To change the data in the 'myColumn' column, you must do the following:

 // first change the cell in the visible part of grid myGrid.jqGrid('setCell', rowid, 'myColumn', newValue); // now change the internal local data var dataArray = myGrid.jqGrid('getGridParam', 'data'), indexes = myGrid.jqGrid('getGridParam', '_index'); dataArray[indexes[rowid]].myColumn = newValue; 

UPDATED . You can use the documented getLocalRow method to change local data:

 // first change the cell in the visible part of grid myGrid.jqGrid('setCell', rowid, 'myColumn', newValue); // now change the internal local data myGrid.jqGrid('getLocalRow', rowid).myColumn = newValue; 
+30
04 Feb '12 at 22:50
source share

For everyone who came here from Google, here is the updated answer!

The index is important, which you can get by calling the getInd-Method. Because rowID! = Index localRowData. (expression rowId: jqg204, Index: 5)

EDIT: if you set the "key: true" to colmodel, you can set your own rowId (different from my example "jqg ###", usually PK from the database table)

 var ind = myGrid.getInd(rowId); var localRowData = myGrid.jqGrid('getLocalRow', ind); localRowData.myColumn = newValue; 

hope this helps!

0
Jul 01 '14 at 18:23
source share

I had a similar problem:
I needed to update the string with some user action (it doesn't matter).
To do this, I needed to know the exact row from the data object, even after some filtering of the table.
Therefore, I found a way to determine which row was changed - I added the RowID property for each element of the data object in the loadComplete event:

 loadComplete: function () { if (firstRun) { firstRun = false; var dataArray = $('#jqGrid').jqGrid('getGridParam', 'data'); $(dataArray).each(function (index) { dataArray[index].RowID = index + 1; }); } } 

And now, in the formatting code, I was able to access rData.RowID to determine the exact line on which the action was taken and to get / set its data representation

0
Jul 11 '16 at 16:57
source share



All Articles