1. 程式人生 > 其它 >easyui datagrid 單擊單元格可編輯

easyui datagrid 單擊單元格可編輯

親測可用,原文參考地址:https://www.jeasyui.net/demo/332.html

$.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); for (var i = 0; i < fields.length; i++) { var col = $(this).datagrid('getColumnOption', fields[i]); col.editor = col.editor1; } }); } });
var editIndex = undefined; function endEditing() { if (editIndex == undefined) { return true } if ($('#datagrid').datagrid('validateRow', editIndex)) { $('#datagrid').datagrid('endEdit', editIndex); editIndex = undefined; return true; } else { return false; } } function onClickCell(index, field) { if (endEditing()) { $('#datagrid').datagrid('selectRow', index) .datagrid('editCell', { index: index, field: field }); editIndex = index; } }