简体   繁体   English

更改为编辑模式时如何禁用对jqGrid行的自动聚焦

[英]how to disable the automatic focus on jqGrid row when it is changed to edit mode

In my grid, when the "Add" button on grid toolbar is clicked, a new empty row will be added into grid. 在我的网格中,当单击网格工具栏上的“添加”按钮时,新的空行将被添加到网格中。 Also, all rows will be changed to edit mode. 同样,所有行都将更改为编辑模式。

My problem is that there is an automatic focus on row when it is changed to edit mode. 我的问题是,当更改为编辑模式时,会自动关注行。 I change the mode of row from the top of grid to the bottom. 我将行的模式从网格的顶部更改为底部。 So the grid always focus to the row on the bottom when the change finishes. 因此,更改完成后,网格始终会集中在底部的行上。 But the new empty row is at the top of grid. 但是,新的空行位于网格的顶部。 So user cannot see the new empty in case of there are many rows in grid. 因此,如果网格中有很多行,用户将看不到新的空白。

Here is my function to change row to edit mode: 这是我将行更改为编辑模式的功能:

    function Grid_EditMode(event, grid) {
    var g;
    if (grid !== null && grid !== undefined) {
        g = grid;
    } else {
        g = $(this);
    }

    HideFilterRow(g);

    var ids = g.jqGrid('getDataIDs');

    for (var i = 0; i < ids.length; i++) {
        var cl = ids[i];
        g.editRow(cl);
    }

    g.jqGrid('resetSelection');

    $('input[id*=Date]').datepicker();
    $('input[id*=Date]').dateEntry({ spinnerImage: '' });
    //change button status
    $('#pager' + g.attr('id') + " [id*='btnGridAdd']").removeClass('pagerBtn');
    $('#pager' + g.attr('id') + " [id*='btnGridEdit']").removeClass('pagerBtn');
    $('#pager' + g.attr('id') + " [id*='btnGridDelete']").removeClass('pagerBtn');
    $('#pager' + g.attr('id') + " [id*='btnGridReset']").removeClass('pagerBtn');
    $('#pager' + g.attr('id') + " [id*='btnGridEdit']").addClass('pagerBtn');

}

Is there any way to disable the focus when changing the row to edit mode? 将行更改为编辑模式时,有什么方法可以禁用焦点?

Note that this problem only occurs on IE, not on chrome. 请注意,此问题仅在IE上发生,而不在chrome上发生。 I'm using the jqGrid 4.5.2 我正在使用jqGrid 4.5.2

jqGrid 4.5.2 is very old version. jqGrid 4.5.2是非常旧的版本。 It was published 2.5 years ago. 它于2.5年前出版。 editRow supports focusField parameter starting with version 4.7. editRow从版本4.7开始支持focusField参数。 If could be Boolean or Number (column index) in jqGrid 4.7. 在jqGrid 4.7中,if可以是Boolean还是Number(列索引)。 Free jqGrid allows the usage of String (column name) and, starting with 4.10.0, Event or DOM element as the value of focusField parameter (see the answer and this one ). 免费的jqGrid允许使用String (列名),并且从4.10.0开始,将Event或DOM元素用作focusField参数的值(请参见答案该内容 )。

In your case one can use focusField: true option of editRow . 在你的情况下,可以使用focusField: true的选项editRow You need just change g.editRow(cl); 您只需要更改g.editRow(cl); to g.editRow(cl, {focusField: false}); g.editRow(cl, {focusField: false}); if you would use jqGrid 4.7 or higher. 如果要使用jqGrid 4.7或更高版本。 I would recommend you to use the latest version (4.10.0) of free jqGrid. 我建议您使用免费的jqGrid的最新版本(4.10.0)。 If you can't upgrade to newer version of jqGrid then you can set the focus to another editing field manually after the last call of editRow . 如果无法升级到jqGrid的较新版本,则可以在上次调用editRow之后将焦点手动设置到另一个编辑字段。 You can add the following code after the loop where you call editRow 您可以在调用editRow的循环之后添加以下代码

$("#" + ids[0])
    .find("input,textarea,select,button,object,*[tabindex]")
    .filter(":input:visible:not(:disabled)")
    .first()
    .focus();

$("#" + ids[0]) get the first row ( <tr> ), then one find all child elements which can have focus, filter for visible and not disabled elements and finally set the focus on the first from the elements. $("#" + ids[0])获取第一行( <tr> ),然后查找所有可以具有焦点的子元素,过滤可见且未禁用的元素,最后将焦点设置为该元素中的第一。

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

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