Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

javascript - Prevent editing of a specific editable row's cell in inline-edit mode

In jqGrid, I'm working in inline-edit mode.

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}); 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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: 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;
}

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:

enter image description here

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...