【问题标题】:jqgrid edit and add rows with "tab" keyjqgrid 使用“tab”键编辑和添加行
【发布时间】:2011-01-20 11:04:14
【问题描述】:

我是 jqgrid 的新手,我正在尝试使用“tab”键在网格中导航。 我希望能够编辑一行,当我编辑该行中的最后一个单元格时,如果我单击 tab 键,它将保存当前行更改(在客户端,而不是通过单击 enter)并设置将焦点移到下一行并编辑它的单元格,当我到达最后一行和单元格时,选项卡单击将添加一个新行并使其处于编辑模式。

我尝试过行内编辑,然后是单元格编辑,但总是卡住... 如何才能做到这一点?

提前致谢。

【问题讨论】:

    标签: jqgrid


    【解决方案1】:

    我不知道您目前拥有什么,但我对此进行了测试并且它有效。由于您没有提及最初是如何开始编辑网格的,所以我在 ready 事件中手动完成了,您只需使用 selIRow var 跟踪当前正在编辑的行。

    var selIRow = 1; //keep track of currently edited row
                     //initialized to 1 for testing purposes
    
        $(document).ready(function () {
            $("#jqGrid").jqGrid({
                datatype: 'local',
                colNames: ['Inv No', 'Date', 'Client', 'Amount', 'Tax', 'Total', 'Notes'],
                colModel: [
                    { name: 'id', index: 'id', width: 60, editable: true },
                    { name: 'invdate', index: 'invdate', width: 90, editable: true },
                    { name: 'name', index: 'name', width: 100, editable: true },
                    { name: 'amount', index: 'amount', width: 80, editable: true },
                    { name: 'tax', index: 'tax', width: 80, editable: true },
                    { name: 'total', index: 'total', width: 80, editable: true },
                    { name: 'note', index: 'note', width: 150, editable: true,
                        //Place this code in the col options of the last column in your grid
                        // it listens for the tab button being pressed
                        editoptions: {
                            dataInit: function (elem) { $(elem).focus(function () { this.select(); }) },
                            dataEvents: [
                                {
                                    type: 'keydown',
                                    fn: function (e) {
                                        var key = e.charCode || e.keyCode;
                                        if (key == 9)//tab
                                        {
                                            var grid = $('#jqGrid');
                                            //Save editing for current row
                                            grid.jqGrid('saveRow', selIRow, false, 'clientArray');
                                            //If at bottom of grid, create new row
                                            if (selIRow++ == grid.getDataIDs().length) {
                                                grid.addRowData(selIRow, {});
                                            }
                                            //Enter edit row for next row in grid
                                            grid.jqGrid('editRow', selIRow, false, 'clientArray');
                                        }
                                    }
                                }
                            ]
                        }
                    }
                ],
            });
        });
    

    here 对 tab 事件的回答归功于 kajo 的回答。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    • 2011-08-01
    • 2016-07-16
    • 1970-01-01
    相关资源
    最近更新 更多