easyui datagrid实现通用编辑

其他章节
function
BillEdit(Jquerygrd) { var self = this; this.grd = Jquerygrd this.editIndex = undefined this.GetCurrentIndex=function (){ let index=null let row =this.grd.datagrid("getSelected") if(row!=null) index=this.grd.datagrid("getRowIndex", row) return index } // this.grdid = grdclassid //默认方法 this.endEditing = function () { if (this.editIndex == undefined) { return true } if (this.grd.datagrid('validateRow', this.editIndex)) { this.grd.datagrid('endEdit', this.editIndex); this.editIndex = undefined; return true; } else { return false; } } //带默认值追加 this.appendRow=function (obj){ appendObj=obj if (!obj) appendObj={} if (this.endEditing()) { this.grd.datagrid('appendRow', appendObj); this.editIndex = this.grd.datagrid('getRows').length - 1; this.grd.datagrid('selectRow', this.editIndex) .datagrid('beginEdit', this.editIndex); } } //带默认值插入 this.insertRow=function (obj){ appendObj=obj if (!obj) appendObj={} //debugger index=this.GetCurrentIndex(); if (this.endEditing()){ if (index ==null) { this.grd.datagrid('appendRow',appendObj); this.editIndex=this.grd.datagrid('getRows').length-1; } else{ this.grd.datagrid('insertRow',{index:index,row:appendObj}); this.editIndex = index; } this.grd.datagrid('selectRow', this.editIndex) .datagrid('beginEdit', this.editIndex); } } this.onClickRow = function (idx) { index=this.GetCurrentIndex(); //debugger if (this.editIndex != index) { if (this.endEditing()) { this.grd.datagrid('selectRow', index) .datagrid('beginEdit', index); this.editIndex = index; } else { this.grd.datagrid('selectRow', this.editIndex); } } } this.removeit = function () { //debugger this.editIndex=this.GetCurrentIndex(); if (this.editIndex == undefined ||this.editIndex==null) { alert("请先选择要删除的行") return } this.grd.datagrid('cancelEdit', this.editIndex) .datagrid('deleteRow', this.editIndex); this.editIndex = undefined; } this.accept = function () { if (this.endEditing()) { this.grd.datagrid('acceptChanges'); } } this.reject = function () { this.grd.datagrid('rejectChanges'); this.editIndex = undefined; } this.getChanges = function () { var rows = this.grd.datagrid('getChanges'); return rows } ///一行的全部绑定上 this.bindTextBlur = function () { var editors = this.grd.datagrid("getEditors", this.editIndex); for (var i = 0; i < editors.length; i++) { editors[i].target.bind('blur', function () { self.accept() }) } } }

 

posted @ 2023-11-20 14:55  伪装大牛  阅读(135)  评论(0编辑  收藏  举报