I'm trying to update a cell in jqgrid permanently upon loading. I know I can use setCell but that only updates the value for that page. If I come back to the page if I don't explicit perform another setCell for the cell the old value is shown. I've also tried setRowData but it appears to be doing the same thing. I'm using the loadonce as my approach is to 1) load the data 2) modify a few values of the data based on some criteria 3) show the modified values. As I'm using loadonce shouldn't there be a way to modify a cell permanently in this session?

我正在尝试在加载时永久更新jqgrid中的单元格。我知道我可以使用setCell,但只更新该页面的值。如果我没有明确地为单元格执行另一个setCell,则返回页面,显示旧值。我也尝试过setRowData,但似乎做了同样的事情。我正在使用loadonce,因为我的方法是1)加载数据2)根据一些标准修改几个数据值3)显示修改后的值。因为我使用loadonce不应该有办法在这个会话中永久修改单元格?

UPDATE:

Putting in my code that isn't giving an error but failing to iterate through all 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 cycling through all items in the array that are locally loaded. For example, if page size is set to 30, the alert(j) returns 30, despite how many items I have locally loaded. However, if I refresh the graph the j is the correct number. Why is the behavior of getGridParam different in each case?

这不是循环遍历本地加载的数组中的所有项目。例如,如果页面大小设置为30,则警报(j)返回30,尽管我在本地加载了多少项目。但是,如果我刷新图形,则j是正确的数字。为什么getGridParam的行为在每种情况下都不同?

3 个解决方案

#1


30

If you use loadonce: true you should know where the local data will be hold by jqGrid. jqGrid has two options: data and _index. The data is array of items where every item has the name property as the name property of the columns from colModel. If you need find the item by id (rowid) you can use _index[rowid] to the the item with the rowid in the data array. So to change the data in the column 'myColumn' you should do the following:

如果你使用loadonce:true,你应该知道jqGrid将保存本地数据的位置。 jqGrid有两个选项:data和_index。数据是项目数组,其中每个项目都具有name属性作为colModel列的名称属性。如果需要通过id(rowid)找到项目,可以使用_index [rowid]到数据数组中带有rowid的项目。因此,要更改“myColumn”列中的数据,您应该执行以下操作:

// 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 documented getLocalRow method to change the local data:

更新:您可以使用记录的getLocalRow方法更改本地数据:

// 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;

更多相关文章

  1. 键盘功能无法处理数据表搜索
  2. 点击JSON数据加载Galleria画廊。我需要新鲜的眼睛来看我的错误
  3. 如何使用ajax GET或POST方法将数据传递到amazon lambda节点。js
  4. 加载函数加载页面但不能对数据执行任何操作
  5. jQuery $ajax 传中文数据到action乱码解决方法
  6. 使用jquery tablesorter插件,有一个选中项目的下拉框
  7. 导入地址簿联系人,存储在数组中并保存到数据库
  8. Twitter在模式窗口中引导数据表程序
  9. jquery mobile界面数据刷新

随机推荐

  1. android studio 错误: 找不到符号 符号:
  2. 【 Android '四大组件' 】篇 -- Activity
  3. 2.5.6 使用progressDialog创建进度对话框
  4. 关于android xml文件中 android:id="@+id
  5. 【Android(安卓)NDK】(一)Hello World!
  6. android自定义title
  7. Android——使用GridView制作二维布局界
  8. Android 选择文件并返回路径
  9. Android学习之 sildingmenu
  10. 【转】android中Textview如何限制在一行