SetRowData和DirtyCells [英] SetRowData and DirtyCells

查看:71
本文介绍了SetRowData和DirtyCells的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SetRowData在jqGrid中设置一些行数据

I'm using SetRowData to set some row data in a jqGrid

jqColModel  = gJqGrid.jqGrid('getGridParam','colModel');
rowData = gJqGrid.jqGrid('getRowData', rowid);
for (var i=0; i<newData.length; i++){
    rowData[jqColModel[i+1].name] = newData[i];
}
gJqGrid.jqGrid('setRowData', rowid, rowData);

这按预期工作.正在使用newData对象中的值更新jqGrid行.

This is working as expected. The jqGrid row is being updated with the values from the newData object.

然后我尝试使用

jqRows = gJqGrid.jqGrid('getChangedCells', 'dirty');

但是这似乎不起作用.我正在尝试汇总所有更改并创建一个自定义保存事件

but this doesn't seem to be working. I'm trying to batch up all the changes and create a custom save event

我的网格定义如下

$(gJqSel_Table).jqGrid({
      caption     : 'jqGrid'
    , datatype    : 'local'
    , loadonce    : true 
    , data        : formattedLineData
    , colNames    : customColNames
    , colModel    : customColModel
    , autoencode  : true 
    , rowNum      : 1000 
    , keys        : true 
    , sortable    : false 
    , hidegrid    : false 
    , multiselect : false 
    , altRows     : false 
    , height      : '100%'
    , autowidth   : true 
    , shrinkToFit : true
    , cellEdit    : gSettings.editMode
    , cellsubmit  : 'clientArray'
    , afterEditCell : function (rowid) {
        var $editControl = $("#" + rowid).find("input, select, textarea");

        if ($editControl){
            $editControl.on('paste', function(e) {
                GridPaste(e, rowid);
            });
        }
    }
});

有人可以提供一些有关我如何做的指导

Can someone provide some guidance about how I can

  • 使用JSON对象设置行的所有单元格值

  • use a JSON object to set all the cell values of a row

将行中的每个单元格标记为脏单元,以便getChangedCells方法知道值已更改?

flag each cell in the row as dirty so that the getChangedCells method knows that the values have changed?

推荐答案

进一步阅读jqGrid文档后,我发现了这一点

After more reading of the jqGrid documentation I found this

setRowData

setRowData

在编辑行或单元格时不要使用此方法.这将 设置内容并覆盖输入元素.

Do not use this method when you are editing the row or cell. This will set the content and overwrite the input elements.

http://www.trirand.com/jqgridwiki/doku. php?id = wiki:方法

更改我的代码以使用setCell方法有效

Changing my code to use the setCell method works

  • 单元格值已更新
  • 单元格被标记为脏单元,并包含在getChangedCells结果中
  • Cell value is updated
  • Cell is marked as dirty and included in the getChangedCells results

我的代码如下

jqColModel = gJqGrid.jqGrid('getGridParam','colModel');
for (var i=0; i<newData.length; i++){
    colName = jqColModel[i].name;
    gJqGrid.jqGrid('setCell', rowid, colName, newData[i], 'dirty-cell');
}

已更新

Updated

正如@Oleg在评论中指出的那样,我还必须添加以下内容以将jqGrid line 标记为已

As @Oleg pointed out in the comments, I also had to add the following to mark the jqGrid line as edited:

gJqGrid.setRowData(rowid, false, 'edited');

这篇关于SetRowData和DirtyCells的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆