easyui 设置onClickCell editor的焦点问题

本文探讨使用EasyUI编辑网格时遇到的焦点设置问题。详细介绍了JavaScript代码实现,并分享了解决方案,即针对特定类型的编辑器调整获得焦点的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用easyUi editGrid 发现 设置 单机后 获得焦点无效(个人觉得巨坑,明明照着 easyui 官网撸的怎么就不能获的焦点了呢!!)
javascript 如下:

function onClickCell(index,field){
            IsCheckFlag=false;
              if (editIndex != index){
                if (endEditing()){
                    $('#dg').datagrid('beginEdit', index);
                    editIndex = index;
                    focusEditor(field);//获得焦点
                } else {
                     //$('#dg').datagrid('selectRow', editIndex); 
                }
            }else{
                //单机同一行  选择不同 列
                focusEditor(field);
            }  
        }
        //单击行的时候 取消选中效果
        var IsCheckFlag=true;
        function onSelect (rowIndex, rowData) {
                    if (!IsCheckFlag) {
                          IsCheckFlag = true;
                          $("#dg").datagrid("unselectRow", rowIndex);
                    }
         }
        function focusEditor(field){
            console.log(field);
                var editor = $('#dg').datagrid('getEditor', {index:editIndex,field:field});
            if (editor){
                editor.target.focus();
                $(editor.target).focus();
                 $(editor.target).focus().bind('blur', function () {
                       alert("什么时候取消了 事件????"); 
                  });

            } else {
                var editors = $('#dg').datagrid('getEditors',editIndex);
                if (editors.length){
                    editors[0].target.focus();
                }
            }
}   

grid 如下:

<table id="dg" class="easyui-datagrid" title="<h>收件材料</h>" style="width:100%;height:auto;"
            data-options="
                singleSelect: false,
                striped:true,
                fit : true,
                rownumbers : true,
                toolbar: '#tb',
                url: '******',
                method: 'get',
                onClickCell:onClickCell,
                onSelect:onSelect
            ">
        <thead>
            <tr>
                <th data-options="field:'ID',width:80,hidden:true">id</th>
                <th data-options="field:'ck',checkbox:true"></th>
                <th data-options="field:'ORDERINDEX',sortable:'true',width:80,align:'center',editor:{type:'numberbox',options:{}},hidden:true">顺序</th>
                <th data-options="field:'NAME',width:367,align:'center',editor:{type:'textbox',options:{}}">收件名称</th>
                <th data-options="field:'TYPE',width:190,
                        formatter: function(v, r, i) {
                                    return type[v];
                        },
                        editor:{
                            type:'combobox',
                            options:{
                                valueField:'value',
                                textField:'text',
                                method:'get',
                                data:types,

                            }
                        }">收件类型</th>

                <th data-options="field:'COPYNUM',width:80,align:'center',editor:{type:'numberbox',options:{}}">份数</th>
                <th data-options="field:'PAGENUM',width:80,align:'center',editor:{type:'numberbox',options:{}}">页数</th>
                <th data-options="field:'SCANNUM',width:80,align:'center',editor:{type:'numberbox',options:{}}">扫描数</th>
                <th data-options="field:'PAGERANGE',width:80,align:'center'">页次</th>
                <th data-options="field:'BZ',width:300,align:'center',editor:'textbox'">备注信息</th>
             </tr>
        </thead>
    </table>

包含括js 调试 esitor.targer 显示为: input元素, 到这里我疯了。。。 就为了个获得焦点事件

最后了个例子, 发现
这里写图片描述
官网的例子 type 为 “text”,然后 我将 type 换成 “text” 发现可行。

最后 才发现 easyui de “textbox” 和 ”numberbox “
不能正常的获取 焦点,最后 通过观察 页面元素,将 获取焦点事件改为:
这里写图片描述
获取焦点 没问题了。(后续版本的 easyui 可能支持 textbox 点击事件)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值