1 /*单元编辑代码开始 */ 2 $.extend($.fn.datagrid.methods, { 3 editCell : function(jq, param) { 4 return jq.each(function() { 5 var opts = $(this).datagrid('options'); 6 var fields = $(this).datagrid('getColumnFields', true).concat( 7 $(this).datagrid('getColumnFields')); 8 for (var i = 0; i < fields.length; i++) { 9 var col = $(this).datagrid('getColumnOption', fields[i]);10 col.editor1 = col.editor;11 if (fields[i] != param.field) {12 col.editor = null;13 }14 }15 $(this).datagrid('beginEdit', param.index);16 for (var i = 0; i < fields.length; i++) {17 var col = $(this).datagrid('getColumnOption', fields[i]);18 col.editor = col.editor1;19 }20 });21 }22 });23 24 var editIndex = undefined;25 function endEditing() {26 if (editIndex == undefined) {27 return true28 }29 if (Obj.datagrid.datagrid('validateRow', editIndex)) {30 Obj.datagrid.datagrid('endEdit', editIndex);31 editIndex = undefined;32 return true;33 } else {34 return false;35 }36 }37 function onClickCell(index, field, value) {38 if (endEditing()) {39 Obj.datagrid.datagrid('selectRow', index).datagrid(40 'editCell', {41 index : index,42 field : field43 });44 editIndex = index;45 }46 }47 function onAfterEdit(rowIndex, rowData, changes) {48 var hasValueChanged = false;49 for ( var property in changes) {50 hasValueChanged = true;51 }52 if (hasValueChanged == true) {53 $.post(Obj.editURL, rowData, function(data) {54 if (data["status"] == 1) {55 //console.log("status 1");56 } else {57 //console.log(data["info"]);58 }59 }, "json");60 }61 }62 /* 单元编辑代码结束 */ datagrid 直接用 写法如下
onClickCell : onClickCell, //点击 onAfterEdit : onAfterEdit