防止以内联编辑模式编辑特定的可编辑行的单元格 [英] Prevent editing of a specific editable row's cell in inline-edit mode

查看:265
本文介绍了防止以内联编辑模式编辑特定的可编辑行的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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.

推荐答案

属性可编辑对于所有行都是通用的,但该值仅由 editRow 方法使用, initialize 内联编辑。因此,您可以根据 setColProp 动态更改可编辑属性的值(例如答案)。在每次调用 editRow 之前,设置可编辑属性的正确值非常重要。 。在答案中,您可以看到相应的代码示例和演示。

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.

UPDATED :如果您使用 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时,注释列才可在演示中编辑:

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:

如果你有数据类型:json 数据类型: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.

这篇关于防止以内联编辑模式编辑特定的可编辑行的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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