如何将焦点设置到单击以在 jqgrid 中开始内联编辑的单元格 [英] How to set focus to cell which was clicked to start inline edit in jqgrid

查看:20
本文介绍了如何将焦点设置到单击以在 jqgrid 中开始内联编辑的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 jqgrid 中,内联编辑通过双击单元格来进行.光标位于第一个可编辑列.第二次单击需要将光标放置到被单击的单元格上.

In jqgrid inline editing is stared by double clicking in a cell. Cursor is positioned to first editable column. Second click in required to place cursor to the cell which was clicked.

如何将光标放在被点击开始内联编辑的单元格上?在单元格编辑模式下,单击的单元格正确接收焦点.

How to put cursor to the cell which was clicked to start inline edit? In cell edit mode clicked cell receives focus properly.

function beginInlineEdit(rowID, afterSave) {
    var grid2 = $("#grid");
    if (rowID && rowID !== lastSelectedRow) {
        var scrollPosition = $("#grid").closest(".ui-jqgrid-bdiv").scrollLeft();
        cancelEditing($("#grid"));
        lastSelectedRow = rowID;
        setTimeout(function () {
            grid2.closest(".ui-jqgrid-bdiv").scrollLeft(scrollPosition);
        }, 100);
    }
    $("tr#" + lastSelectedRow + " div.ui-inline-edit, " + "tr#" + lastSelectedRow + " div.ui-inline-del").hide();
    $("tr#" + lastSelectedRow + " div.ui-inline-save, " + "tr#" + lastSelectedRow + " div.ui-inline-cancel").show();

    $("#grid").jqGrid('editRow', lastSelectedRow, true, null, null, null,
                 { _dokdata: FormData },
                 afterSave,
                 errorfunc,
                 function () {
                     cancelEditing($("#grid"));
                     setFocusToGrid();
                 }
             );
}

更新 1

我在 IE9 中尝试了 Oleg 演示.问题:

I tried Oleg demo in IE9. Issues:

  1. 双击复选框列仍将焦点放在第一列.

  1. double-clicking in checkbox column still puts focus to first column.

我减小了浏览窗口的宽度并向右滚动.单击最右边的列会导致奇怪的快速闪烁:网格滚动到最左边的位置,然后又回到右边的位置.

I decreased browse window width and scrolled right. Clicking in righmost column causes strange rapid flashing: grid scrolls to leftmost position and after that back to right position.

如何解决这些问题?

推荐答案

演示来自答案一个>.演示可以完全满足您的需要,或者您可以根据自己的目的修改演示.

Look at the demo from the answer. Either the demo do exactly what you need or you can modify the demo to your purposes.

更新:1) 您是否尝试过我的原始演示,或者您尝试在您的代码中使用所描述的想法?在我的环境中(在不同的计算机上)demo 把重点放在单击的单元格.它在 IE9(本机甚至兼容模式)、IE8、Google Chrome 13、Safari 5.1、Opera 11.50、Firefox 3.6.20 和 Nightly 9.0a1(Firefox 的下一个版本)中都能正常工作.

UPDATED: 1) Do you tried my original demo or you tried to use the described idea in your code? In my environment (on different computers) the demo put the focus in the clicked cell. It works correct in IE9 (in native and even in the compatibility mode), IE8, Google Chrome 13, Safari 5.1, Opera 11.50, Firefox 3.6.20 and Nightly 9.0a1 (next version of Firefox).

2) 在第一个编辑位置滚动网格然后到单击的单元格是正确的行为.默认情况下,jqGrid 内联编辑将焦点设置在第一个编辑单元格上,然后在 editRow,我们将焦点更改为单击的单元格.

2) The scrolling grid at the first editing position first and then to the clicked cell is the correct behavior. Per default jqGrid inline editing set the focus on the first editing cell and then, inside of oneditfunc callback function of editRow, we change the focus to clicked cell.

这篇关于如何将焦点设置到单击以在 jqgrid 中开始内联编辑的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆