easyui可编辑行失去焦点后操作

function initYS()
        {
            $('#dg').datagrid({
                //width: 700, 
                loadMsg: "数据加载中,请稍后...",
                width: 400,
                height: 170,
                singleSelect: true,
                pageList: [30, 50, 100],
                url: “”,
                collapsible: true,
                nowrap: false,
                rownumbers: true,
                fitColumns: true,
                toolbar: '#aa',
                idField: "ID",
                onClickRow: onClickRow,
                columns: [[
                    { field: 'ID', title: '编号', width: 100, align: 'center', hidden: 'true' },
                    { field: 'YS', title: '颜色', width: 300, align: 'center', editor: { type: 'validatebox' } },
                    { field: 'handler', title: '操作', width: 123, align: 'center', formatter: formatOper }
                ]],
                onLoadSuccess: function (data) {
                    if (data.total < 1) {
                        $(this).datagrid('deleteRow', 0);

                    }
                }

            });
        }
var editIndex = undefined;
        function endEditing() {
            if (editIndex == undefined) { return true }
            if ($('#dg').datagrid('validateRow', editIndex)) {
                var ed = $('#dg').datagrid('getEditor', { index: editIndex, field: 'ID' });
                $('#dg').datagrid('endEdit', editIndex);
                editIndex = undefined;
                return true;
            } else {
                return false;
            }
        }
        function onClickRow(index) {
            if (editIndex != index) {
                if (endEditing()) {
                    $('#dg').datagrid('selectRow', index)
							.datagrid('beginEdit', index);
//获取编辑行
 var editors = $('#dg').datagrid('getEditors', index);
                    var sfgzEditor = editors[0];
//绑定失焦事件并取消可编辑状态
 sfgzEditor.target.bind('blur', function () {
                        $('#dg').datagrid('selectRow', index)
							.datagrid('endEdit', index);
                        editIndex = undefined;
                        //update();
                    });
                    editIndex = index;
                } else {
                    $('#dg').datagrid('selectRow', editIndex);
                }
            }
        }

你可能感兴趣的:(web,easyui)