Permalink
Browse files

fix: pro-IUAPDESIGN-247:友云采:grid增加参数控制只改变ui不修改datatable

  • Loading branch information...
1 parent 3bc43c8 commit 576fc1d0ee673ff46b653b982f9952c3c60aba61 liuyk committed Oct 27, 2016
Showing with 104 additions and 38 deletions.
  1. +76 −31 js/component/keroa-grid.js
  2. +15 −2 js/component/keroa-switch.js
  3. +13 −5 js/core/valueMixin.js
@@ -139,7 +139,11 @@ var GridAdapter = BaseAdapter.extend({
//IE8有问题,所以需要重新创建div,将上面的代码直接拷贝
oThis.createDefaultEdit(eType,eOptions,options,viewModel,column);
}
- var comp = oThis.editComponent[column.field]
+ var comp = oThis.editComponent[column.field];
+ var rowId = obj.rowObj['$_#_@_id'];
+ var row = oThis.dataTable.getRowByRowId(rowId);
+ var index = oThis.dataTable.getRowIndex(row);
+ comp.options.rowIndex = index;
if (!comp){
$(obj.element).parent().focus();
return
@@ -520,19 +524,41 @@ var GridAdapter = BaseAdapter.extend({
var onRowSelectedFun = this.gridOptions.onRowSelected;
// 选中
this.gridOptions.onRowSelected = function(obj) {
- var rowId = oThis.grid.dataSourceObj.rows[obj.rowIndex].value['$_#_@_id'];
- var index = oThis.dataTable.getIndexByRowId(rowId);
- if(oThis.grid.options.multiSelect){
- oThis.dataTable.addRowsSelect([index]);
- }else{
- oThis.dataTable.setRowSelect(index);
+ if(!oThis.silence){
+ var rowId = oThis.grid.dataSourceObj.rows[obj.rowIndex].value['$_#_@_id'];
+ var index = oThis.dataTable.getIndexByRowId(rowId);
+ if(oThis.grid.options.multiSelect){
+ oThis.dataTable.addRowsSelect([index]);
+ }else{
+ oThis.dataTable.setRowSelect(index);
+ }
}
-
if(onRowSelectedFun){
onRowSelectedFun.call(oThis,obj);
}
};
this.dataTable.on(DataTable.ON_ROW_SELECT, function(event) {
+
+ var gridSelectRows = [];
+ $.each(oThis.grid.getSelectRows(),function(){
+ gridSelectRows.push(this);
+ });
+ $.each(gridSelectRows,function(){
+ var rowId = this['$_#_@_id'];
+ var unSelectFlag = true;
+ $.each(event.rowIds,function(){
+ if(this == rowId)
+ unSelectFlag = false;
+ })
+ if(unSelectFlag){
+ var index = oThis.grid.getRowIndexByValue('$_#_@_id',rowId);
+ oThis.silence = true;
+ oThis.grid.setRowUnselect(index);
+ oThis.silence = false;
+ }
+ })
+
+
/*index转化为grid的index*/
$.each(event.rowIds, function() {
var index = oThis.grid.getRowIndexByValue('$_#_@_id',this);
@@ -544,6 +570,8 @@ var GridAdapter = BaseAdapter.extend({
}
}
});
+
+
});
//全选
@@ -559,9 +587,11 @@ var GridAdapter = BaseAdapter.extend({
// 反选
var onRowUnSelectedFun = this.gridOptions.onRowUnSelected;
this.gridOptions.onRowUnSelected = function(obj) {
- var rowId = oThis.grid.dataSourceObj.rows[obj.rowIndex].value['$_#_@_id'];
- var index = oThis.dataTable.getIndexByRowId(rowId);
- oThis.dataTable.setRowUnSelect(index);
+ if(!oThis.silence){
+ var rowId = oThis.grid.dataSourceObj.rows[obj.rowIndex].value['$_#_@_id'];
+ var index = oThis.dataTable.getIndexByRowId(rowId);
+ oThis.dataTable.setRowUnSelect(index);
+ }
if(onRowUnSelectedFun){
onRowUnSelectedFun.call(oThis,obj);
}
@@ -586,13 +616,15 @@ var GridAdapter = BaseAdapter.extend({
var onRowFocusFun = this.gridOptions.onRowFocus;
// focus
this.gridOptions.onRowFocus = function(obj) {
- var rowId = oThis.grid.dataSourceObj.rows[obj.rowIndex].value['$_#_@_id'];
- var index = oThis.dataTable.getIndexByRowId(rowId);
+ if(!oThis.silence){
+ var rowId = oThis.grid.dataSourceObj.rows[obj.rowIndex].value['$_#_@_id'];
+ var index = oThis.dataTable.getIndexByRowId(rowId);
- if(oThis.grid.options.rowClickBan) {
- oThis.dataTable.setRowFocus(index, true);
- } else {
- oThis.dataTable.setRowFocus(index);
+ if(oThis.grid.options.rowClickBan) {
+ oThis.dataTable.setRowFocus(index, true);
+ } else {
+ oThis.dataTable.setRowFocus(index);
+ }
}
if(onRowFocusFun){
@@ -616,9 +648,11 @@ var GridAdapter = BaseAdapter.extend({
// 反focus
var onRowUnFocusFun = this.gridOptions.onRowUnFocus;
this.gridOptions.onRowUnFocus = function(obj) {
- var rowId = oThis.grid.dataSourceObj.rows[obj.rowIndex].value['$_#_@_id'];
- var index = oThis.dataTable.getIndexByRowId(rowId);
- oThis.dataTable.setRowUnFocus(index);
+ if(!oThis.silence){
+ var rowId = oThis.grid.dataSourceObj.rows[obj.rowIndex].value['$_#_@_id'];
+ var index = oThis.dataTable.getIndexByRowId(rowId);
+ oThis.dataTable.setRowUnFocus(index);
+ }
if(onRowUnFocusFun){
onRowUnFocusFun.call(oThis,obj);
}
@@ -685,10 +719,13 @@ var GridAdapter = BaseAdapter.extend({
//oThis.grid.editClose();
});
- // 删除行,只考虑viewModel传入grid
-// this.gridOptions.onRowDelete = function(obj){
-// dataTable.removeRow(obj.index);
-// };
+ this.gridOptions.onRowDelete = function(obj){
+ if(!oThis.silence){
+ var row = obj.row;
+ var datatableIndex = oThis.getDatatableRowIndexByGridRow(row.value);
+ oThis.dataTable.removeRow(datatableIndex);
+ }
+ };
this.dataTable.on(DataTable.ON_DELETE, function(event) {
/*index转化为grid的index*/
var gridIndexs = new Array();
@@ -706,13 +743,15 @@ var GridAdapter = BaseAdapter.extend({
// 数据改变
var onValueChangeFun = this.gridOptions.onValueChange;
this.gridOptions.onValueChange = function(obj) {
- var row = oThis.getDataTableRow(oThis.grid.dataSourceObj.rows[obj.rowIndex].value)
- if(row){
- if($.type(obj.newValue) == 'object') {
- row.setValue(obj.field, obj.newValue.trueValue);
- row.setMeta(obj.field, 'display', obj.newValue.showValue);
- } else {
- row.setValue(obj.field,obj.newValue);
+ if(!oThis.silence){
+ var row = oThis.getDataTableRow(oThis.grid.dataSourceObj.rows[obj.rowIndex].value)
+ if(row){
+ if($.type(obj.newValue) == 'object') {
+ row.setValue(obj.field, obj.newValue.trueValue);
+ row.setMeta(obj.field, 'display', obj.newValue.showValue);
+ } else {
+ row.setValue(obj.field,obj.newValue);
+ }
}
}
if(onValueChangeFun){
@@ -1515,6 +1554,12 @@ var GridAdapter = BaseAdapter.extend({
return row
},
+ getDatatableRowIndexByGridRow: function(gridRow){
+ var rowId = gridRow['$_#_@_id']
+ var rowIndex = this.dataTable.getIndexByRowId(rowId)
+ return rowIndex;
+ },
+
setEnable: function(enable){
this.grid.setEditable(enable);
},
@@ -31,6 +31,17 @@ var SwitchAdapter = BaseAdapter.extend({
self.modelValueChange(value)
})
+ var self = this;
+ //处理只读
+ if (this.options['enable'] && (this.options['enable'] == 'false' || this.options['enable'] == false)){
+ this.setEnable(false);
+ }else {
+ this.dataModel.refEnable(this.field).subscribe(function (value) {
+ self.setEnable(value);
+ });
+ this.setEnable(this.dataModel.isEnable(this.field));
+ }
+
},
@@ -45,9 +56,11 @@ var SwitchAdapter = BaseAdapter.extend({
},
setEnable: function (enable) {
if (enable === true || enable === 'true') {
- this.enable = true
+ this.enable = true;
+ this.comp.enable();
} else if (enable === false || enable === 'false') {
- this.enable = false
+ this.enable = false;
+ this.comp.disable();
}
}
})
View
@@ -1,7 +1,7 @@
/**
* Module : Kero Value Mixin
* Author : Kvkens(yueming@yonyou.com)
- * Date : 2016-08-08 15:58:49
+ * Date : 2016-08-08 15:58:49
*/
@@ -11,10 +11,18 @@ var ValueMixin = {
// 如果存在行对象则处理数据都针对此行进行处理
if(this.options.rowIndex > -1){
- var obj = {
- index : this.options.rowIndex,
- fieldName : this.field
- }
+ // 添加监听,判断当前field并且为当前行的情况下才修改值
+ this.dataModel.on(DataTable.ON_VALUE_CHANGE, function(obj) {
+ if(self.field == obj.field){
+ var rowId = obj.rowId;
+ var row = self.dataModel.getRowByRowId(rowId);
+ var index = self.dataModel.getRowIndex(row);
+ if(index == self.options.rowIndex){
+ self.modelValueChange(obj.newValue);
+ }
+ }
+ });
+
var rowObj = this.dataModel.getRow(this.options.rowIndex);
if(rowObj){
this.modelValueChange(rowObj.getValue(this.field));

0 comments on commit 576fc1d

Please sign in to comment.