1

我使用 jeasyui 创建一个数据网格,网格有最后一行可以编辑数据,每次用户按 Enter 时,我保存数据并插入新行让用户输入另一个数据。我的问题是如何通过 jquery 在下一个文本框中设置焦点,因为输入文本会生成自动化 ID,我无法通过 find 函数找到它。

我的代码:

    $(function(){
        $('#test').datagrid({
            width:700,
            height:350,
            url:'/getlistdemoajax'<%-- '<%=Configuration
                .getCssServerPath("/resources/vinamilk/datagrid_data.json")%>' --%>,
            sortName: 'code',
            sortOrder: 'asc',
            remoteSort: false,
            idField:'code',
            singleSelect:true,
            columns:[[
                {field:'code',title:'TT',width:40,editor:'text'},
                {field:'name',title:'code',width:110,editor:'text'},
                {field:'name',title:'name',width:110,editor:'text'},
                {field:'name',title:'name2',width:110,editor:'text'},
                {field:'name',title:'name2',width:110,editor:'text'},
                {field:'name',title:'name2',width:110,editor:'text'},

            ]],
            pagination:true,
            onLoadSuccess:function(){
                loadSuccess = false;
                $('#test').datagrid('appendRow',{
                    code:'',
                    name:'',
                    })
                $('#test').datagrid('beginEdit', $('#test').datagrid('getRows').length-1);

        },
        onClickRow:function(rowIndex){
            var rowss = $('#test').datagrid('getSelected');
            var selected = $('#test').datagrid('getSelected');
            if (selected){

                if (selected.code ==''){
                    $('#test').datagrid('beginEdit', rowIndex);
                }
            }
            }

        });
        $.extend($('#test').datagrid.defaults.editors, {  
            text: {  
                init: function(container, options){  
                    var input = $('<input type="text" class="datagrid-editable-input" onkeypress="saveData(event);">').appendTo(container);  
                    return input;  
                },  
                getValue: function(target){  
                    return $(target).val();  
                },  
                setValue: function(target, value){  
                    $(target).val(value);  
                },  
                resize: function(target, width){  
                    var input = $(target);  
                    if ($.boxModel == true){  
                        input.width(width - (input.outerWidth() - input.width()));  
                    } else {  
                        input.width(width);  
                    }  
                }  
            }  
        });  
    function saveData(e)
    {
        // look for window.event in case event isn't passed in
        if (typeof e == 'undefined' && window.event) { e = window.event; }
        if (e.keyCode == 13)
        {
            $('#test').datagrid('acceptChanges');
            //Create one row
            $('#test').datagrid('appendRow',{
                    code:'',
                    name:'',
                    })
            $('#test').datagrid('beginEdit', $('#test').datagrid('getRows').length-1);
        }
    }
4

0 回答 0