2011-01-20 154 views
1

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

我尝试过在线编辑,然后用单元格编辑,但总是卡住... 这怎么可以做到?

在此先感谢。

回答

2

我不知道你目前有什么,但我测试了这一点,它的工作原理。既然你没有提到你最初是如何开始编辑网格的,我已经在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的标签事件转到kajo的回答。

+0

我在http://stackoverflow.com/questions/6781612/how-to-enalbe-up-down-arrow-keys-in-jqgrid-inline-ed发布了相关的问题将代码示例扩展为在内联编辑中启用向上/向下箭头键? – Andrus 2011-07-27 11:58:11

相关问题