function BillEdit(Jquerygrd) {标签:function,index,通用,easyui,return,datagrid,grd,editIndex From: https://www.cnblogs.com/SoftWareIe/p/17843960.html
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 (){
if (this.endEditing()) {
this.grd.datagrid('appendRow', {});
this.editIndex = this.grd.datagrid('getRows').length - 1;
this.grd.datagrid('selectRow', this.editIndex)
.datagrid('beginEdit', this.editIndex);
}
}
this.insertRow=function (){
//debugger
index=this.GetCurrentIndex();
if (this.endEditing()){
if (index ==null) {
this.grd.datagrid('appendRow',{});
this.editIndex=this.grd.datagrid('getRows').length-1;
}
else{
this.grd.datagrid('insertRow',{index:index,row:{}});
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()
})
}
}
}