//-----------------------------------------------------------------
/**************************************************************@调用方法:$("#dg").datagrid().datagrid('enableCellEditing'); *@功能: Datagrid扩展方法InitEditGrid{支持单元格编辑}*@date: 2016-10-20*@user; hwm add by**************************************************************/MCBaseDBGrid.InitEditGrid = function (mygrid) { $.extend($.fn.datagrid.methods, { editCell: function (jq, param) { return jq.each(function () { var opts = $(this).datagrid('options'); var fields = $(this).datagrid('getColumnFields', true).concat($(this).datagrid('getColumnFields')); for (var i = 0; i < fields.length; i++) { var col = $(this).datagrid('getColumnOption', fields[i]); col.editor1 = col.editor; if (fields[i] != param.field) { col.editor = null; } } $(this).datagrid('beginEdit', param.index); var ed = $(this).datagrid('getEditor', param); if (ed) { if ($(ed.target).hasClass('textbox-f')) { $(ed.target).textbox('textbox').focus(); $(ed.target).textbox('textbox').select(); } else if ($(ed.target).hasClass('combogrid-editable-input')) { $(ed.target).parent().find(".combo-text").focus(); $(ed.target).parent().find(".combo-text").select(); //绑定key事件 $(ed.target).parent().find(".combo-text").bind('keydown', function (e) { if (e.keyCode == 13) { } }); } else { $(ed.target).focus(); $(ed.target).select(); } } for (var i = 0; i < fields.length; i++) { var col = $(this).datagrid('getColumnOption', fields[i]); col.editor = col.editor1; } }); }, //定义修改 enableCellEditing: function (jq) { return jq.each(function () { var dg = $(this); var opts = dg.datagrid('options'); opts.oldOnClickCell = opts.onClickCell; opts.onClickCell = function (index, field) { mygrid.editorIndex = index; mygrid.editorField = field;if (opts.editIndex != undefined) {
if (dg.datagrid('validateRow', opts.editIndex)) { dg.datagrid('endEdit', opts.editIndex); opts.editIndex = undefined; } else { return; } } dg.datagrid('selectRow', index).datagrid('editCell', { index: index, field: field }); opts.oldOnClickCell.call(this, index, field); } }); } });}