how to end inline edit started with formatter edit action button if other row is clicked in jqgrid

前端 未结 1 493
独厮守ぢ
独厮守ぢ 2020-12-20 08:06

Inline editing is started using edit formatter action button. If clicked in other row, old row remains in inline edit mode.

How to end old row indline edit if clicke

相关标签:
1条回答
  • 2020-12-20 08:50

    You are right. It seems bug in the formatter:"actions" of the current version of jqGrid. If you examine the source code you will find no variable which saves the information about the last editing row. So depend on the implementation of your code which use formatter:"actions" you can has either multiple editing rows:

    enter image description here

    or at least wrong icons in the old editing row

    enter image description here

    and you will not be able to edit the previous editing icon ever more (because you have no "edit" action icon).

    In the demo I suggest as the workaround to cancel the previous editing unsaved row in both onSelectRow jqGrid event and in the onEdit event of the formatter:'actions'. The corresponding code fragment look as following

    var grid=$("#list"),
        lastSel,
        cancelEditing = function(myGrid) {
            var lrid;
            if (typeof lastSel !== "undefined") {
                // cancel editing of the previous selected row if it was in editing state.
                // jqGrid hold intern savedRow array inside of jqGrid object,
                // so it is safe to call restoreRow method with any id parameter
                // if jqGrid not in editing state
                myGrid.jqGrid('restoreRow',lastSel);
    
                // now we need to restore the icons in the formatter:"actions"
                lrid = $.jgrid.jqID(lastSel);
                $("tr#" + lrid + " div.ui-inline-edit, " + "tr#" + lrid + " div.ui-inline-del").show();
                $("tr#" + lrid + " div.ui-inline-save, " + "tr#" + lrid + " div.ui-inline-cancel").hide();
            }
        };
    
    grid.jqGrid({
        // ...
        colModel:[
            {name:'act',index:'act',width:55,align:'center',sortable:false,formatter:'actions',
                formatoptions:{
                    keys: true,
                    delOptions: myDelOptions,
                    onEdit: function (id) {
                        if (typeof (lastSel) !== "undefined" && id !== lastSel) {
                            cancelEditing(grid);
                        }
                        lastSel = id;
                    }
                }},
            ...
        ],
        onSelectRow: function(id) {
            if (typeof (lastSel) !== "undefined" && id !== lastSel) {
                cancelEditing($(this));
            }
            lastSel = id;
        }
    });
    

    In the demo I use inline editing on double clicking on the grid row in addition to the action formatter. It is not really required, but both can work together without any conflicts.

    0 讨论(0)
提交回复
热议问题