fixed #3339
This commit is contained in:
parent
eeeceb5446
commit
5d164b03ec
3 changed files with 47 additions and 18 deletions
|
@ -34,6 +34,7 @@
|
||||||
<span :class="[prefixCls + '-filter']">
|
<span :class="[prefixCls + '-filter']">
|
||||||
<i class="ivu-icon ivu-icon-funnel" :class="{on: getColumn(rowIndex, index)._isFiltered}"></i>
|
<i class="ivu-icon ivu-icon-funnel" :class="{on: getColumn(rowIndex, index)._isFiltered}"></i>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<div slot="content" :class="[prefixCls + '-filter-list']" v-if="getColumn(rowIndex, index)._filterMultiple">
|
<div slot="content" :class="[prefixCls + '-filter-list']" v-if="getColumn(rowIndex, index)._filterMultiple">
|
||||||
<div :class="[prefixCls + '-filter-list-item']">
|
<div :class="[prefixCls + '-filter-list-item']">
|
||||||
<checkbox-group v-model="getColumn(rowIndex, index)._filterChecked">
|
<checkbox-group v-model="getColumn(rowIndex, index)._filterChecked">
|
||||||
|
@ -133,8 +134,8 @@
|
||||||
},
|
},
|
||||||
scrollBarCellClass(){
|
scrollBarCellClass(){
|
||||||
let hasRightFixed = false;
|
let hasRightFixed = false;
|
||||||
for(var i in this.headRows){
|
for(let i in this.headRows){
|
||||||
for(var j in this.headRows[i]){
|
for(let j in this.headRows[i]){
|
||||||
if(this.headRows[i][j].fixed === 'right') {
|
if(this.headRows[i][j].fixed === 'right') {
|
||||||
hasRightFixed=true;
|
hasRightFixed=true;
|
||||||
break;
|
break;
|
||||||
|
@ -205,7 +206,13 @@
|
||||||
// 因为表头嵌套不是深拷贝,所以没有 _ 开头的方法,在 isGroup 下用此列
|
// 因为表头嵌套不是深拷贝,所以没有 _ 开头的方法,在 isGroup 下用此列
|
||||||
getColumn (rowIndex, index) {
|
getColumn (rowIndex, index) {
|
||||||
const isGroup = this.columnRows.length > 1;
|
const isGroup = this.columnRows.length > 1;
|
||||||
return isGroup ? this.columns[rowIndex] : this.headRows[rowIndex][index];
|
|
||||||
|
if (isGroup) {
|
||||||
|
const id = this.headRows[rowIndex][index].__id;
|
||||||
|
return this.columns.filter(item => item.__id === id)[0];
|
||||||
|
} else {
|
||||||
|
return this.headRows[rowIndex][index];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -103,7 +103,7 @@
|
||||||
import ExportCsv from './export-csv';
|
import ExportCsv from './export-csv';
|
||||||
import Locale from '../../mixins/locale';
|
import Locale from '../../mixins/locale';
|
||||||
import elementResizeDetectorMaker from 'element-resize-detector';
|
import elementResizeDetectorMaker from 'element-resize-detector';
|
||||||
import { getAllColumns, convertToRows, convertColumnOrder } from './util';
|
import { getAllColumns, convertToRows, convertColumnOrder, getRandomStr } from './util';
|
||||||
|
|
||||||
const prefixCls = 'ivu-table';
|
const prefixCls = 'ivu-table';
|
||||||
|
|
||||||
|
@ -178,6 +178,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
|
const colsWithId = this.makeColumnsId(this.columns);
|
||||||
return {
|
return {
|
||||||
ready: false,
|
ready: false,
|
||||||
tableWidth: 0,
|
tableWidth: 0,
|
||||||
|
@ -186,13 +187,13 @@
|
||||||
compiledUids: [],
|
compiledUids: [],
|
||||||
objData: this.makeObjData(), // checkbox or highlight-row
|
objData: this.makeObjData(), // checkbox or highlight-row
|
||||||
rebuildData: [], // for sort or filter
|
rebuildData: [], // for sort or filter
|
||||||
cloneColumns: this.makeColumns(),
|
cloneColumns: this.makeColumns(colsWithId),
|
||||||
minWidthColumns:[],
|
minWidthColumns:[],
|
||||||
maxWidthColumns:[],
|
maxWidthColumns:[],
|
||||||
columnRows: this.makeColumnRows(false),
|
columnRows: this.makeColumnRows(false, colsWithId),
|
||||||
leftFixedColumnRows: this.makeColumnRows('left'),
|
leftFixedColumnRows: this.makeColumnRows('left', colsWithId),
|
||||||
rightFixedColumnRows: this.makeColumnRows('right'),
|
rightFixedColumnRows: this.makeColumnRows('right', colsWithId),
|
||||||
allColumns: getAllColumns(this.columns), // for multiple table-head, get columns that have no children
|
allColumns: getAllColumns(colsWithId), // for multiple table-head, get columns that have no children
|
||||||
showSlotHeader: true,
|
showSlotHeader: true,
|
||||||
showSlotFooter: true,
|
showSlotFooter: true,
|
||||||
bodyHeight: 0,
|
bodyHeight: 0,
|
||||||
|
@ -828,9 +829,17 @@
|
||||||
});
|
});
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
makeColumns () {
|
// 修改列,设置一个隐藏的 id,便于后面的多级表头寻找对应的列,否则找不到
|
||||||
|
makeColumnsId (columns) {
|
||||||
|
return columns.map(item => {
|
||||||
|
if ('children' in item) item.children = this.makeColumnsId(item.children);
|
||||||
|
item.__id = getRandomStr(6);
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
makeColumns (cols) {
|
||||||
// 在 data 时,this.allColumns 暂时为 undefined
|
// 在 data 时,this.allColumns 暂时为 undefined
|
||||||
let columns = deepCopy(getAllColumns(this.columns));
|
let columns = deepCopy(getAllColumns(cols));
|
||||||
let left = [];
|
let left = [];
|
||||||
let right = [];
|
let right = [];
|
||||||
let center = [];
|
let center = [];
|
||||||
|
@ -869,8 +878,8 @@
|
||||||
return left.concat(center).concat(right);
|
return left.concat(center).concat(right);
|
||||||
},
|
},
|
||||||
// create a multiple table-head
|
// create a multiple table-head
|
||||||
makeColumnRows (fixedType) {
|
makeColumnRows (fixedType, cols) {
|
||||||
return convertToRows(this.columns, fixedType);
|
return convertToRows(cols, fixedType);
|
||||||
},
|
},
|
||||||
setMinMaxColumnRows (){
|
setMinMaxColumnRows (){
|
||||||
let minWidthColumns=[];
|
let minWidthColumns=[];
|
||||||
|
@ -964,13 +973,14 @@
|
||||||
columns: {
|
columns: {
|
||||||
handler () {
|
handler () {
|
||||||
// todo 这里有性能问题,可能是左右固定计算属性影响的
|
// todo 这里有性能问题,可能是左右固定计算属性影响的
|
||||||
this.allColumns = getAllColumns(this.columns);
|
const colsWithId = this.makeColumnsId(this.columns);
|
||||||
|
this.allColumns = getAllColumns(colsWithId);
|
||||||
this.cloneColumns = this.makeColumns();
|
this.cloneColumns = this.makeColumns();
|
||||||
this.setMinMaxColumnRows();
|
this.setMinMaxColumnRows();
|
||||||
|
|
||||||
this.columnRows = this.makeColumnRows(false);
|
this.columnRows = this.makeColumnRows(false, colsWithId);
|
||||||
this.leftFixedColumnRows = this.makeColumnRows('left');
|
this.leftFixedColumnRows = this.makeColumnRows('left', colsWithId);
|
||||||
this.rightFixedColumnRows = this.makeColumnRows('right');
|
this.rightFixedColumnRows = this.makeColumnRows('right', colsWithId);
|
||||||
this.rebuildData = this.makeDataWithSortAndFilter();
|
this.rebuildData = this.makeDataWithSortAndFilter();
|
||||||
this.handleResize();
|
this.handleResize();
|
||||||
},
|
},
|
||||||
|
|
|
@ -79,3 +79,15 @@ const convertToRows = (columns, fixedType = false) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export {convertToRows};
|
export {convertToRows};
|
||||||
|
|
||||||
|
const getRandomStr = function (len = 32) {
|
||||||
|
const $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
||||||
|
const maxPos = $chars.length;
|
||||||
|
let str = '';
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
str += $chars.charAt(Math.floor(Math.random() * maxPos));
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
};
|
||||||
|
|
||||||
|
export {getRandomStr};
|
Loading…
Add table
Reference in a new issue