Prevent editing of a specific editable row#39;s cell in inline-edit mode(防止在线编辑模式下编辑特定可编辑行的单元格)
问题描述
在 jqGrid 中,我正在内联编辑模式下工作.
In jqGrid, I'm working in inline-edit mode.
当用户尝试编辑一行时(单击笔操作图标)我想阻止({editable: false}
)根据另一个单元格的内容编辑特定可编辑行的单元格在这一行.
When the user try to edit a row(click on the pen action icon) I want to prevent({editable: false}
) the editing of a specific editable row's cell based on another cell's content in this row.
grid.setColProp('myColumn',{editable:false});
对我不利,因为这将禁用对所有网格行中的myColumn"的编辑,我想申请它仅在当前编辑的行上.
grid.setColProp('myColumn',{editable:false});
is not good for me because this will disable the editing of 'myColumn' in all the grids's rows and I want to apply it only on the currently edited row.
推荐答案
属性 editable
的值对所有行都是通用的,但该值只会被 editRow 使用
code> 方法,其中 initialize 内联编辑.因此,您可以根据 setColProp
动态更改 editable
属性的值(如 答案).请务必在每次调用 editRow
之前设置正确的 editable
属性值.在答案中可以看到对应的代码示例和demo.
The value of the property editable
is common for all rows, but the value will be used only by editRow
method which initialize inline editing. So you can change the value of editable
property dynamically with respect of setColProp
(like in the answer). It's important that you set the correct value of the editable
property before every call of editRow
. In the answer you can see corresponding code example and the demo.
更新:如果你使用 formatter: "actions"
那么你可以子类化" $.fn.fmatter.rowactions
调用onclick
处理程序.下面你可以看到相应代码的示例
UPDATED: If you use formatter: "actions"
then you can "subclass" the $.fn.fmatter.rowactions
called in onclick
handler. Below you can see an example of the corresponding code
var orgRowActions = $.fn.fmatter.rowactions;
$.fn.fmatter.rowactions = function (rid, gid, act, pos) {
var $grid = $("#" + $.jgrid.jqID(gid)),
rowData = $grid.jqGrid("getLocalRow", rid),
isNonEditable = false,
result;
// we can test any condition and change
// editable property of any column
if (act === "edit" && parseFloat(String(rowData.tax)) <= 20) {
$grid.jqGrid("setColProp", "note", {editable: false});
isNonEditable = true;
}
result = orgRowActions.call(this, rid, gid, act, pos);
if (isNonEditable) {
// reset the setting to original state
$grid.jqGrid("setColProp", "note", {editable: true});
}
return result;
}
您可以在这里找到相应的演示.只有当tax"列中的值是<= 20时,note"列才可在演示中
The corresponding demo you will find here. The "note" column is editable in the demo only if the value from the "tax" column is <= 20:
如果你有 datatype: "json"
或 datatype: "xml"
而不使用 loadonce: true
你应该替换调用getLocalRow
对上述代码中getRowData
或getCell
的调用.
If you would have datatype: "json"
or datatype: "xml"
without usage of loadonce: true
you should replace call of getLocalRow
to the call of getRowData
or getCell
in the above code.
这篇关于防止在线编辑模式下编辑特定可编辑行的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:防止在线编辑模式下编辑特定可编辑行的单元格
基础教程推荐
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01