简体   繁体   English

将类似Excel的功能添加到已可编辑单元格的jqgrid中

[英]Adding Excel like functionality to jqgrid of already editable cells

I have a jqGrid with only certain columns that are editable and I would like to be able to implement functionality similar to excel when you press tab and enter. 我有一个jqGrid,其中只有某些可编辑的列,并且我希望能够在按Tab键并输入时实现类似于excel的功能。 These columns are editable from the start, because I call editRow on every row in loadComplete, so that the user may click in any one of the cells in these columns and change the information. 这些列从一开始就是可编辑的,因为我在loadComplete的每一行上都调用editRow,以便用户可以单击这些列中的任何单元格并更改信息。 I would like it to be such that when you press tab the cursor goes to the next editable cell in the current row until it gets to the end and upon pressing tab again, goes to the first editable cell of the next row; 我希望这样,当您按下Tab键时,光标会移至当前行中的下一个可编辑单元格,直到到达末尾为止;再次按下Tab键时,光标将移至下一行的第一个可编辑单元格中; and upon pressing enter goes to the first editable cell of the next row no matter what cell you happen to be in of the previous row. 然后,无论您碰巧位于上一行的哪个单元格中,按下Enter键都将转到下一行的第一个可编辑单元格。 Every time cell focus is changed, data is saved to the server. 每次更改单元格焦点时,数据都会保存到服务器。

I've been doing quite a bit of research, but none of it has worked. 我已经做了很多研究,但是没有一个起作用。 I have the functionality for each keypress in the colModel under editoptions and dataEvents as a keydown event that checks to see which button has been pressed and then executes the appropriate code. 我在colModel中的editoptions和dataEvents下具有每个按键功能,作为一个按键按下事件,该事件检查查看已按下哪个按钮,然后执行适当的代码。 The first thing I tried used the editCell method of jqGrid where I passed it the row and column of the next cell I would like to move the cursor to, but that didn't work and I think it is because I've already called editRow on every row. 我尝试使用的第一件事是jqGrid的editCell方法,在该方法中我将光标要移到的下一个单元格的行和列传递给了它,但这没有用,我认为这是因为我已经调用了editRow每行。 I've also tried changing the focus to the cell I'm trying to go to by using $.click() or $.focus() but that has not worked either. 我还尝试过通过使用$ .click()或$ .focus()将焦点更改为要尝试转到的单元格,但这也没有用。

Something extra to note is that when these columns are blurred, I recompute the column totals on the client side. 另外需要注意的是,当这些列模糊时,我将在客户端重新计算列总数。 I have tried putting the different things I've tried to change focus inside setTimeout but that hasn't worked either. 我尝试将尝试更改焦点的不同内容放到setTimeout中,但这也不起作用。

I basically would like to keep it where all of the cells in the columns that I want to be editable are editable at any time and the user may either click on that specific cell or tab/enter over to it to edit it. 我基本上希望将其保留在我想可编辑的列中的所有单元格都可随时编辑的位置,并且用户可以单击该特定单元格或对其进行标签/输入以对其进行编辑。 This is how it looks for clarification: 这是需要澄清的方式:

http://cl.ly/2W3E1U3i1k3K0W2Y0r0n http://cl.ly/2W3E1U3i1k3K0W2Y0r0n

Thanks for the help! 谢谢您的帮助!

I was able to figure it out and I'm not sure why it took me so long to figure out. 我能够弄清楚,但我不确定为什么花这么长时间才弄清楚。 Nothing that jqgrid provided worked and I had tried many different things from jQuery and I finally found something that works: jqgrid所提供的一切都不起作用,我尝试了jQuery的许多不同操作,最后发现了行得通的方法:

{
    type: 'keydown',
    fn: function(e) {
        var key = e.charCode || e.keyCode;
        //TAB
        if(key == jq.ui.keyCode.TAB) {
             setTimeout(function() { 
               jq('#' + currentRowId + '_nextColName').focus();
               jq('#' + currentRowId + '_nextColName').select(); 
             }, 500);
        }
        //ENTER
        else if (key == jq.ui.keyCode.ENTER) {
             var nextRow = parseInt(currentRowId) + 1;
             jq('#' + currentRowId + '_thisColName').blur();
             jq('#' + nextRow + '_firstColName').select();
        }
    }
}

This makes it so that tab takes you to the next column and enter always takes you to the first column of the next row while maintaining that all of the cells are always editable and you can click on any editable cell at any time. 这样一来,制表符会将您带到下一行,而输入总是将您带到下一行的第一列,同时保持所有单元格始终都是可编辑的,并且您可以随时单击任何可编辑的单元格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM