gpt4 book ai didi

javascript - 对于值不变的单元格调用什么函数?

转载 作者:行者123 更新时间:2023-12-03 08:13:45 24 4
gpt4 key购买 nike

对未更改的值调用 saveCell 时会调用什么函数?如果单元格的先前值是 100 并且在未更改的值(即 100)上调用 saveCell,则 beforeSaveCell 也不会beforeSubmitCell 也不会被调用。我该如何处理这个案子?

我正在使用jqGrid 4.6.0

最佳答案

单元格编辑的工作原理如下:jqGrid将可编辑行/单元格的内容保存在jqGrid savedRow内部参数中,类型为数组。 saveCell 方法(或使用内联编辑中的 savedRow)将可编辑单元格中的当前值与之前保存的内容(来自 savedRow )。如果在编辑期间没有进行任何更改,则将调用 restoreCell。仅当 Ajax 调用将发送到服务器(cellsubmit: "remote")或者如果需要在本地保存更改(cellsubmit: "clientArray")。在服务器或本地成功保存数据后,将调用回调 afterSaveCell

您写道,您在代码中显式调用saveCell。因此,您可以在调用 saveCell 之前检查单元格是否已更改。您需要做的是包括像下面的代码那样的测试:

// below code uses $grid, which is jQuery wrapper to jqGrid (like $grid = $("#grid"))
// it uses additionally iRow and iCol variables which you use as parameters
// of the call of saveCell

var $t = $grid[0], // $t is the DOM of the grid
p = $grid.jqGrid("getGridParam"), // get reference to all jqGrid parameters
getTdByColumnIndex = function (tr, iCol) {
// the function getTdByColumnIndex return jQuery wrapper
// to one or two <td> elements. If frozen column is used
// and the column iCol is frozen then the function
// returns the wrapper to two <td> elements: one from
// frozen div and another from original grid
var $t = this, frozenRows = $t.grid.fbRows;
return $((frozenRows != null && frozenRows[0].cells.length > iCol ?
frozenRows[tr.rowIndex] :
tr).cells[iCol]);
},
tr = $t.rows[iRow], rowid = tr.id, $tr = $(tr), cm = p.colModel[iCol],
savedRow = p.savedRow,
fr = savedRow.length >= 1 ? 0 : null,
nm = cm.name, v, cc = getTdByColumnIndex.call($t, tr, iCol);

v = $.jgrid.getEditedValue.call($t, cc, cm, !cm.formatter);
if (v !== savedRow[fr].v) {
// the cell is changed you can call saveCell
// and you will be sure that the changes will be saved
} else {
// the cell is not changed
// you can call
// $grid.jqGrid("restoreCell", iRow, iCol);
// directly
}

上面的代码是我从免费的jqGrid的现有代码中得到的。另外,首先应该测试一下iCol列是否可编辑。如果您确切知道哪种可编辑类型具有该列以及您是否使用卡住列,那么您可以简化您的代码

关于javascript - 对于值不变的单元格调用什么函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34042984/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com