Permalink
Browse files

feat: grid增加参数nullField用于过滤datatable中存在但是grid中不应存在的字段(主要针对主子表情况下的子表字段)

  • Loading branch information...
LiuYueKai committed Jul 4, 2017
1 parent 5e2686b commit e303507a68d3e2182aa70e760560ace68429ffa9
Showing with 46 additions and 8 deletions.
  1. +25 −6 src/js/gridCompOperateRow.js
  2. +3 −1 src/js/gridCompSet.js
  3. +18 −1 src/js/ut_utility.js
@@ -16,10 +16,12 @@ const isCheckedHeaderRow = function() {
* 添加一行
*/
const addOneRow = function(row, index) {
if (typeof this.options.filterDataFun == 'function') {
var rows = this.options.filterDataFun.call(this, [row]);
row = rows[0];
}
row = this.getGridRow(row);
var oThis = this,
displayFlag = 'none',
rowObj = {},
@@ -203,6 +205,7 @@ const addRows = function(rows, index) {
if (typeof this.options.filterDataFun == 'function') {
rows = this.options.filterDataFun.call(this, rows);
}
this.editClose();
var htmlStr = '',
htmlStrmultiSelect = '',
@@ -211,6 +214,11 @@ const addRows = function(rows, index) {
oThis = this,
l = this.dataSourceObj.rows.length,
endFlag = false;
var newRows = [];
$.each(rows, function() {
newRows.push(oThis.getGridRow(this))
})
rows = newRows;
if (index != 0) {
if (index && index > 0) {
if (l < index)
@@ -346,7 +354,7 @@ const deleteOneRow = function(index) {
return;
var rowValue = row.value;
if (this.showType == 'grid') { //只有grid展示的时候才处理div,针对隐藏情况下还要添加数据
if (this.showType == 'grid' && this.eidtRowIndex != index) { //只有grid展示的时候才处理div,针对隐藏情况下还要添加数据
this.editClose();
}
this.dataSourceObj.rows.splice(index, 1);
@@ -541,18 +549,29 @@ const setRowSelect = function(rowIndex, doms) {
selectDiv = doms['multiSelectDivs'][rowIndex]
else
selectDiv = this.$ele.find('#' + this.options.id + '_content_multiSelect').find('div')[rowIndex]
var beforeSelectFlag = true;
if (typeof this.options.onBeforeRowSelected == 'function') {
var obj = {};
obj.gridObj = this;
obj.rowObj = this.dataSourceObj.rows[rowIndex];
obj.rowIndex = rowIndex;
if (!this.options.onBeforeRowSelected(obj)) {
if (this.options.multiSelect) {
var _input = selectDiv.children[0];
beforeSelectFlag = this.options.onBeforeRowSelected(obj)
}
if (beforeSelectFlag && typeof this.options.onBeforeCreateLeftMul == 'function') {
var obj = {
gridObj: this,
rowObj: this.dataSourceObj.rows[rowIndex]
}
beforeSelectFlag = this.options.onBeforeCreateLeftMul.call(this, obj);
}
if (!beforeSelectFlag) {
if (this.options.multiSelect) {
var _input = selectDiv.children[0];
if (_input)
_input.checked = false;
}
return false;
}
return false;
}
if (!this.options.multiSelect) {
if (this.selectRowsObj && this.selectRowsObj.length > 0) {
View
@@ -50,8 +50,10 @@ const setColumnVisibleByIndex = function(index, visible) {
}
}
var newContentW = this.contentWidth + parseInt(column.options.width);
if(this.showType == 'grid'){
$('#' + this.options.id + '_column_menu_columns_ul li input:eq(' + index + ')')[0].checked = true;
}
$('#' + this.options.id + '_column_menu_columns_ul li input:eq(' + index + ')')[0].checked = true;
}
// 隐藏处理
if (column.options.visible == true && !visible) {
View
@@ -191,6 +191,22 @@ const SortByFun = function(field, sortType, eqCall) {
}
};
const getGridRow = function(row) {
var obj = {};
var nullField = this.options.nullField;
if (nullField) {
if (nullField.indexOf(';') > 0) {
var nullFields = nullField.split(';');
for (var i = 0; i < nullFields.length; i++) {
var f = nullFields[i];
row[f] = null;
}
} else {
row[nullField] = null;
}
}
return row;
};
export const utilFunOjb = {
formatWidth: formatWidth,
@@ -203,5 +219,6 @@ export const utilFunOjb = {
accAdd: accAdd,
getTrIndex: getTrIndex,
getDataTableRowIdByRow: getDataTableRowIdByRow,
SortByFun: SortByFun
SortByFun: SortByFun,
getGridRow: getGridRow
}

0 comments on commit e303507

Please sign in to comment.