1. 程式人生 > >easyui可編輯行失去焦點後操作

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);
                }
            }
        }