Skip to content

Commit

Permalink
feat: grid增加filterDataFun用于在新增数据之前进行过滤
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYueKai committed Apr 12, 2017
1 parent 54d7aa8 commit 3799a5a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/js/dataSourceInit.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const init = function(options, gridComp) {
* 将values转化为rows并进行排序 * 将values转化为rows并进行排序
*/ */
const sortRows = function(field, sortType) { const sortRows = function(field, sortType) {
if (typeof this.gridComp.options.filterDataFun == 'function') {
this.options.values = this.gridComp.options.filterDataFun.call(this, this.options.values);
}
if (this.gridComp.options.showTree) { if (this.gridComp.options.showTree) {
this.treeSortRows(field, sortType); this.treeSortRows(field, sortType);
} else { } else {
Expand Down
46 changes: 28 additions & 18 deletions src/js/gridCompOperateRow.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const isCheckedHeaderRow = function() {
* 添加一行 * 添加一行
*/ */
const addOneRow = function(row, index) { const addOneRow = function(row, index) {
if (typeof this.options.filterDataFun == 'function') {
var rows = this.options.filterDataFun.call(this, [row]);
row = rows[0];
}
var oThis = this, var oThis = this,
displayFlag = 'none', displayFlag = 'none',
rowObj = {}, rowObj = {},
Expand Down Expand Up @@ -136,6 +140,7 @@ const addOneRow = function(row, index) {
this.repairSumRow(); this.repairSumRow();
this.noRowsShowFun(); this.noRowsShowFun();
this.updateLastRowFlag(); this.updateLastRowFlag();
this.resetLeftHeight();
var obj = {}; var obj = {};
obj.begin = index; obj.begin = index;
obj.length = 1; obj.length = 1;
Expand All @@ -152,6 +157,7 @@ const editClose = function() {};
* 添加多行 * 添加多行
*/ */
const addRows = function(rows, index) { const addRows = function(rows, index) {

if (!(this.$ele.data('gridComp') == this)) return; if (!(this.$ele.data('gridComp') == this)) return;
if (this.options.showTree) { if (this.options.showTree) {
// 树表待优化 // 树表待优化
Expand All @@ -161,6 +167,9 @@ const addRows = function(rows, index) {
} }
return; return;
} }
if (typeof this.options.filterDataFun == 'function') {
rows = this.options.filterDataFun.call(this, rows);
}
this.editClose(); this.editClose();
var htmlStr = '', var htmlStr = '',
htmlStrmultiSelect = '', htmlStrmultiSelect = '',
Expand Down Expand Up @@ -279,6 +288,7 @@ const addRows = function(rows, index) {


this.updateLastRowFlag(); this.updateLastRowFlag();
this.isCheckedHeaderRow(); this.isCheckedHeaderRow();
this.resetLeftHeight();
}; };
const createContentOneRowFixed = function(rowObj) { const createContentOneRowFixed = function(rowObj) {
return ''; return '';
Expand Down Expand Up @@ -332,8 +342,8 @@ const deleteOneRow = function(index) {
} }
} }
if (this.showType == 'grid') { //只有grid展示的时候才处理div,针对隐藏情况下还要添加数据 if (this.showType == 'grid') { //只有grid展示的时候才处理div,针对隐藏情况下还要添加数据
$('#' + this.options.id + '_content_div tbody tr:eq(' + index + ')').remove(); $('#' + this.options.id + '_content_div tbody tr[role="row"]:eq(' + index + ')').remove();
$('#' + this.options.id + '_content_fixed_div tbody tr:eq(' + index + ')').remove(); $('#' + this.options.id + '_content_fixed_div tbody tr[role="row"]:eq(' + index + ')').remove();
$('#' + this.options.id + '_content_multiSelect >div:eq(' + index + ')').remove(); $('#' + this.options.id + '_content_multiSelect >div:eq(' + index + ')').remove();
$('#' + this.options.id + '_content_numCol >.u-grid-content-num:eq(' + index + ')').remove(); $('#' + this.options.id + '_content_numCol >.u-grid-content-num:eq(' + index + ')').remove();
this.resetNumCol(); this.resetNumCol();
Expand Down Expand Up @@ -489,10 +499,10 @@ const setRowSelect = function(rowIndex, doms) {
this.selectRowsObj = new Array(); this.selectRowsObj = new Array();
this.selectRowsIndex = new Array(); this.selectRowsIndex = new Array();
if (this.showType == 'grid') { if (this.showType == 'grid') {
$('#' + this.options.id + '_content_tbody tr').removeClass("u-grid-content-sel-row"); $('#' + this.options.id + '_content_tbody tr[role="row"]').removeClass("u-grid-content-sel-row");
$('#' + this.options.id + '_content_tbody tr a').removeClass("u-grid-content-sel-row"); $('#' + this.options.id + '_content_tbody tr[role="row"] a').removeClass("u-grid-content-sel-row");
$('#' + this.options.id + '_content_fixed_tbody tr').removeClass("u-grid-content-sel-row"); $('#' + this.options.id + '_content_fixed_tbody tr[role="row"]').removeClass("u-grid-content-sel-row");
$('#' + this.options.id + '_content_fixed_tbody tr a').removeClass("u-grid-content-sel-row"); $('#' + this.options.id + '_content_fixed_tbody tr[role="row"] a').removeClass("u-grid-content-sel-row");
if (this.options.multiSelect) { if (this.options.multiSelect) {
$('#' + this.options.id + '_content_multiSelect div').removeClass("u-grid-content-sel-row"); $('#' + this.options.id + '_content_multiSelect div').removeClass("u-grid-content-sel-row");
} }
Expand Down Expand Up @@ -588,10 +598,10 @@ const setRowUnselect = function(rowIndex) {
if (this.eidtRowIndex > -1 && this.eidtRowIndex < rowIndex && this.options.editType == 'form') { if (this.eidtRowIndex > -1 && this.eidtRowIndex < rowIndex && this.options.editType == 'form') {
ini++; ini++;
} }
$('#' + this.options.id + '_content_tbody tr:eq(' + ini + ')').removeClass("u-grid-content-sel-row"); $('#' + this.options.id + '_content_tbody tr[role="row"]:eq(' + ini + ')').removeClass("u-grid-content-sel-row");
$('#' + this.options.id + '_content_tbody tr:eq(' + ini + ') a').removeClass("u-grid-content-sel-row"); $('#' + this.options.id + '_content_tbody tr[role="row"]:eq(' + ini + ') a').removeClass("u-grid-content-sel-row");
$('#' + this.options.id + '_content_fixed_tbody tr:eq(' + ini + ')').removeClass("u-grid-content-sel-row"); $('#' + this.options.id + '_content_fixed_tbody tr[role="row"]:eq(' + ini + ')').removeClass("u-grid-content-sel-row");
$('#' + this.options.id + '_content_fixed_tbody tr:eq(' + ini + ') a').removeClass("u-grid-content-sel-row"); $('#' + this.options.id + '_content_fixed_tbody tr[role="row"]:eq(' + ini + ') a').removeClass("u-grid-content-sel-row");
if (this.options.multiSelect) { if (this.options.multiSelect) {
$('#' + this.options.id + '_content_multiSelect >div:eq(' + ini + ')').removeClass("u-grid-content-sel-row"); $('#' + this.options.id + '_content_multiSelect >div:eq(' + ini + ')').removeClass("u-grid-content-sel-row");
} }
Expand Down Expand Up @@ -700,10 +710,10 @@ const setRowFocus = function(rowIndex) {
return false; return false;
} }
} }
$('#' + this.options.id + '_content_tbody tr').removeClass("u-grid-content-focus-row"); $('#' + this.options.id + '_content_tbody tr[role="row"]').removeClass("u-grid-content-focus-row");
$('#' + this.options.id + '_content_tbody tr a').removeClass("u-grid-content-focus-row"); $('#' + this.options.id + '_content_tbody tr[role="row"] a').removeClass("u-grid-content-focus-row");
$('#' + this.options.id + '_content_fixed_tbody tr').removeClass("u-grid-content-focus-row"); $('#' + this.options.id + '_content_fixed_tbody tr[role="row"]').removeClass("u-grid-content-focus-row");
$('#' + this.options.id + '_content_fixed_tbody tr a').removeClass("u-grid-content-focus-row"); $('#' + this.options.id + '_content_fixed_tbody tr[role="row"] a').removeClass("u-grid-content-focus-row");
if (this.options.multiSelect) { if (this.options.multiSelect) {
$('#' + this.options.id + '_content_multiSelect').find('div').removeClass("u-grid-content-focus-row"); $('#' + this.options.id + '_content_multiSelect').find('div').removeClass("u-grid-content-focus-row");
} }
Expand Down Expand Up @@ -766,10 +776,10 @@ const setRowUnFocus = function(rowIndex) {
if (this.eidtRowIndex > -1 && this.eidtRowIndex < rowIndex && this.options.editType == 'form') { if (this.eidtRowIndex > -1 && this.eidtRowIndex < rowIndex && this.options.editType == 'form') {
ini++; ini++;
} }
$('#' + this.options.id + '_content_tbody tr:eq(' + ini + ')').removeClass("u-grid-content-focus-row"); $('#' + this.options.id + '_content_tbody tr[role="row"]:eq(' + ini + ')').removeClass("u-grid-content-focus-row");
$('#' + this.options.id + '_content_tbody tr:eq(' + ini + ') a').removeClass("u-grid-content-focus-row"); $('#' + this.options.id + '_content_tbody tr[role="row"]:eq(' + ini + ') a').removeClass("u-grid-content-focus-row");
$('#' + this.options.id + '_content_fixed_tbody tr:eq(' + ini + ')').removeClass("u-grid-content-focus-row"); $('#' + this.options.id + '_content_fixed_tbody tr[role="row"]:eq(' + ini + ')').removeClass("u-grid-content-focus-row");
$('#' + this.options.id + '_content_fixed_tbody tr:eq(' + ini + ') a').removeClass("u-grid-content-focus-row"); $('#' + this.options.id + '_content_fixed_tbody tr[role="row"]:eq(' + ini + ') a').removeClass("u-grid-content-focus-row");
if (this.options.multiSelect) { if (this.options.multiSelect) {
$('#' + this.options.id + '_content_multiSelect >div:eq(' + ini + ')').removeClass("u-grid-content-focus-row"); $('#' + this.options.id + '_content_multiSelect >div:eq(' + ini + ')').removeClass("u-grid-content-focus-row");
} }
Expand Down

0 comments on commit 3799a5a

Please sign in to comment.