Skip to content

Commit

Permalink
fix: 增加机制datatable通知grid时不再反向通知datatable
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyk committed Nov 2, 2016
1 parent 60c072b commit c14321c
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions js/component/keroa-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ var GridAdapter = BaseAdapter.extend({
}
};
this.dataTable.on(DataTable.ON_ROW_SELECT, function(event) {

// oThis.silence = true;
var gridSelectRows = [];
$.each(oThis.grid.getSelectRows(),function(){
gridSelectRows.push(this);
Expand Down Expand Up @@ -574,18 +574,22 @@ var GridAdapter = BaseAdapter.extend({
}
}
});

// oThis.silence = false;

});

//全选
this.dataTable.on(DataTable.ON_ROW_ALLSELECT, function(event) {
oThis.grid.setAllRowSelect()
// oThis.silence = true;
oThis.grid.setAllRowSelect();
// oThis.silence = false;
});

//全返选
this.dataTable.on(DataTable.ON_ROW_ALLUNSELECT, function(event) {
oThis.grid.setAllRowUnSelect()
// oThis.silence = true;
oThis.grid.setAllRowUnSelect();
// oThis.silence = false;
});

// 反选
Expand All @@ -601,6 +605,7 @@ var GridAdapter = BaseAdapter.extend({
}
};
this.dataTable.on(DataTable.ON_ROW_UNSELECT, function(event) {
// oThis.silence = true;
$.each(event.rowIds, function() {
var index = oThis.grid.getRowIndexByValue('$_#_@_id',this);
var unSelectFlag = true;
Expand All @@ -615,6 +620,7 @@ var GridAdapter = BaseAdapter.extend({
}
}
});
// oThis.silence = false;
});

var onRowFocusFun = this.gridOptions.onRowFocus;
Expand All @@ -636,6 +642,7 @@ var GridAdapter = BaseAdapter.extend({
}
};
this.dataTable.on(DataTable.ON_ROW_FOCUS, function(event) {
// oThis.silence = true;
/*index转化为grid的index*/
var index = oThis.grid.getRowIndexByValue('$_#_@_id',event.rowId);

Expand All @@ -647,6 +654,7 @@ var GridAdapter = BaseAdapter.extend({
oThis.dataTable.setRowUnFocus(oThis.dataTable.getIndexByRowId(event.rowId));
}
}
// oThis.silence = false;
});

// 反focus
Expand All @@ -662,6 +670,7 @@ var GridAdapter = BaseAdapter.extend({
}
};
this.dataTable.on(DataTable.ON_ROW_UNFOCUS, function(event) {
// oThis.silence = true;
var index = oThis.grid.getRowIndexByValue('$_#_@_id',event.rowId);
var unFocusFlag = true;
if(index > -1){
Expand All @@ -670,6 +679,7 @@ var GridAdapter = BaseAdapter.extend({
oThis.dataTable.setRowFocus(oThis.dataTable.getIndexByRowId(event.rowId));
}
}
// oThis.silence = false;
});

// 增行,只考虑viewModel传入grid
Expand All @@ -681,6 +691,7 @@ var GridAdapter = BaseAdapter.extend({
// }
// };
this.dataTable.on(DataTable.ON_INSERT, function(event) {
// oThis.silence = true;
var gridRows = new Array();
$.each(event.rows,function(){
var row = this.data;
Expand All @@ -693,9 +704,11 @@ var GridAdapter = BaseAdapter.extend({
gridRows.push(gridRow);
})
oThis.grid.addRows(gridRows,event.index);
// oThis.silence = false;
});

this.dataTable.on(DataTable.ON_UPDATE, function(event) {
// oThis.silence = true;
$.each(event.rows,function(){
var row = this.data;
var id = this.rowId;
Expand All @@ -707,11 +720,11 @@ var GridAdapter = BaseAdapter.extend({
var index = oThis.grid.getRowIndexByValue('$_#_@_id',id);
oThis.grid.updateRow(index,gridRow);
})

// oThis.silence = false;
});

this.dataTable.on(DataTable.ON_VALUE_CHANGE, function(obj) {

oThis.silence = true;
var id = obj.rowId;
var index = oThis.grid.getRowIndexByValue('$_#_@_id',id);
if(index == -1) {
Expand All @@ -721,6 +734,7 @@ var GridAdapter = BaseAdapter.extend({
var value = obj.newValue;
oThis.grid.updateValueAt(index,field,value);
//oThis.grid.editClose();
oThis.silence = false;
});

this.gridOptions.onRowDelete = function(obj){
Expand All @@ -731,17 +745,21 @@ var GridAdapter = BaseAdapter.extend({
}
};
this.dataTable.on(DataTable.ON_DELETE, function(event) {
// oThis.silence = true;
/*index转化为grid的index*/
var gridIndexs = new Array();
$.each(event.rowIds, function() {
var index = oThis.grid.getRowIndexByValue('$_#_@_id',this);
gridIndexs.push(index);
});
oThis.grid.deleteRows(gridIndexs);
// oThis.silence = false;
});

this.dataTable.on(DataTable.ON_DELETE_ALL, function(event) {
oThis.grid.setDataSource({})
// oThis.silence = true;
oThis.grid.setDataSource({});
// oThis.silence = false;
});

// 数据改变
Expand All @@ -763,6 +781,7 @@ var GridAdapter = BaseAdapter.extend({
}
};
this.dataTable.on('valueChange', function(event) {
// oThis.silence = true;
var field = event.field,
rowId = event.rowId,
oldValue = event.oldValue,
Expand All @@ -771,9 +790,11 @@ var GridAdapter = BaseAdapter.extend({
if(rowIndex > -1){
oThis.grid.updateValueAt(rowIndex,field,newValue);
}
// oThis.silence = false;
});
// 加载数据,只考虑viewModel传入grid
this.dataTable.on(DataTable.ON_LOAD, function(data) {
// oThis.silence = true;
if(data.length > 0){
var values = new Array();

Expand All @@ -792,12 +813,16 @@ var GridAdapter = BaseAdapter.extend({
dataSource['values'] = values;
oThis.grid.setDataSource(dataSource);
}
// oThis.silence = false;
});
this.dataTable.on(DataTable.ON_ENABLE_CHANGE, function(enable) {
// oThis.silence = true;
oThis.grid.setEditable(enable.enable);
// oThis.silence = false;
});

this.dataTable.on(DataTable.ON_ROW_META_CHANGE, function(event){
// oThis.silence = true;
var field = event.field,
meta = event.meta,
row = event.row,
Expand All @@ -819,14 +844,17 @@ var GridAdapter = BaseAdapter.extend({

oThis.grid.updateValueAt(index,field,value,true);
}
// oThis.silence = false;
})

this.dataTable.on(DataTable.ON_META_CHANGE, function(event){
// oThis.silence = true;
var field = event.field
var meta = event.meta
if (meta == 'precision'){
oThis.grid.renderTypeFun({field:field})
}
// oThis.silence = false;
})

this.gridOptions.transMap = {
Expand Down

0 comments on commit c14321c

Please sign in to comment.