Commit 5d164b03ec365265f35d54b57d40954e70db7326
1 parent
eeeceb54
fixed #3339
Showing
3 changed files
with
47 additions
and
18 deletions
Show diff stats
src/components/table/table-head.vue
... | ... | @@ -34,6 +34,7 @@ |
34 | 34 | <span :class="[prefixCls + '-filter']"> |
35 | 35 | <i class="ivu-icon ivu-icon-funnel" :class="{on: getColumn(rowIndex, index)._isFiltered}"></i> |
36 | 36 | </span> |
37 | + | |
37 | 38 | <div slot="content" :class="[prefixCls + '-filter-list']" v-if="getColumn(rowIndex, index)._filterMultiple"> |
38 | 39 | <div :class="[prefixCls + '-filter-list-item']"> |
39 | 40 | <checkbox-group v-model="getColumn(rowIndex, index)._filterChecked"> |
... | ... | @@ -133,8 +134,8 @@ |
133 | 134 | }, |
134 | 135 | scrollBarCellClass(){ |
135 | 136 | let hasRightFixed = false; |
136 | - for(var i in this.headRows){ | |
137 | - for(var j in this.headRows[i]){ | |
137 | + for(let i in this.headRows){ | |
138 | + for(let j in this.headRows[i]){ | |
138 | 139 | if(this.headRows[i][j].fixed === 'right') { |
139 | 140 | hasRightFixed=true; |
140 | 141 | break; |
... | ... | @@ -205,7 +206,13 @@ |
205 | 206 | // 因为表头嵌套不是深拷贝,所以没有 _ 开头的方法,在 isGroup 下用此列 |
206 | 207 | getColumn (rowIndex, index) { |
207 | 208 | const isGroup = this.columnRows.length > 1; |
208 | - return isGroup ? this.columns[rowIndex] : this.headRows[rowIndex][index]; | |
209 | + | |
210 | + if (isGroup) { | |
211 | + const id = this.headRows[rowIndex][index].__id; | |
212 | + return this.columns.filter(item => item.__id === id)[0]; | |
213 | + } else { | |
214 | + return this.headRows[rowIndex][index]; | |
215 | + } | |
209 | 216 | } |
210 | 217 | } |
211 | 218 | }; | ... | ... |
src/components/table/table.vue
... | ... | @@ -103,7 +103,7 @@ |
103 | 103 | import ExportCsv from './export-csv'; |
104 | 104 | import Locale from '../../mixins/locale'; |
105 | 105 | import elementResizeDetectorMaker from 'element-resize-detector'; |
106 | - import { getAllColumns, convertToRows, convertColumnOrder } from './util'; | |
106 | + import { getAllColumns, convertToRows, convertColumnOrder, getRandomStr } from './util'; | |
107 | 107 | |
108 | 108 | const prefixCls = 'ivu-table'; |
109 | 109 | |
... | ... | @@ -178,6 +178,7 @@ |
178 | 178 | } |
179 | 179 | }, |
180 | 180 | data () { |
181 | + const colsWithId = this.makeColumnsId(this.columns); | |
181 | 182 | return { |
182 | 183 | ready: false, |
183 | 184 | tableWidth: 0, |
... | ... | @@ -186,13 +187,13 @@ |
186 | 187 | compiledUids: [], |
187 | 188 | objData: this.makeObjData(), // checkbox or highlight-row |
188 | 189 | rebuildData: [], // for sort or filter |
189 | - cloneColumns: this.makeColumns(), | |
190 | + cloneColumns: this.makeColumns(colsWithId), | |
190 | 191 | minWidthColumns:[], |
191 | 192 | maxWidthColumns:[], |
192 | - columnRows: this.makeColumnRows(false), | |
193 | - leftFixedColumnRows: this.makeColumnRows('left'), | |
194 | - rightFixedColumnRows: this.makeColumnRows('right'), | |
195 | - allColumns: getAllColumns(this.columns), // for multiple table-head, get columns that have no children | |
193 | + columnRows: this.makeColumnRows(false, colsWithId), | |
194 | + leftFixedColumnRows: this.makeColumnRows('left', colsWithId), | |
195 | + rightFixedColumnRows: this.makeColumnRows('right', colsWithId), | |
196 | + allColumns: getAllColumns(colsWithId), // for multiple table-head, get columns that have no children | |
196 | 197 | showSlotHeader: true, |
197 | 198 | showSlotFooter: true, |
198 | 199 | bodyHeight: 0, |
... | ... | @@ -828,9 +829,17 @@ |
828 | 829 | }); |
829 | 830 | return data; |
830 | 831 | }, |
831 | - makeColumns () { | |
832 | + // 修改列,设置一个隐藏的 id,便于后面的多级表头寻找对应的列,否则找不到 | |
833 | + makeColumnsId (columns) { | |
834 | + return columns.map(item => { | |
835 | + if ('children' in item) item.children = this.makeColumnsId(item.children); | |
836 | + item.__id = getRandomStr(6); | |
837 | + return item; | |
838 | + }); | |
839 | + }, | |
840 | + makeColumns (cols) { | |
832 | 841 | // 在 data 时,this.allColumns 暂时为 undefined |
833 | - let columns = deepCopy(getAllColumns(this.columns)); | |
842 | + let columns = deepCopy(getAllColumns(cols)); | |
834 | 843 | let left = []; |
835 | 844 | let right = []; |
836 | 845 | let center = []; |
... | ... | @@ -869,8 +878,8 @@ |
869 | 878 | return left.concat(center).concat(right); |
870 | 879 | }, |
871 | 880 | // create a multiple table-head |
872 | - makeColumnRows (fixedType) { | |
873 | - return convertToRows(this.columns, fixedType); | |
881 | + makeColumnRows (fixedType, cols) { | |
882 | + return convertToRows(cols, fixedType); | |
874 | 883 | }, |
875 | 884 | setMinMaxColumnRows (){ |
876 | 885 | let minWidthColumns=[]; |
... | ... | @@ -964,13 +973,14 @@ |
964 | 973 | columns: { |
965 | 974 | handler () { |
966 | 975 | // todo 这里有性能问题,可能是左右固定计算属性影响的 |
967 | - this.allColumns = getAllColumns(this.columns); | |
976 | + const colsWithId = this.makeColumnsId(this.columns); | |
977 | + this.allColumns = getAllColumns(colsWithId); | |
968 | 978 | this.cloneColumns = this.makeColumns(); |
969 | 979 | this.setMinMaxColumnRows(); |
970 | 980 | |
971 | - this.columnRows = this.makeColumnRows(false); | |
972 | - this.leftFixedColumnRows = this.makeColumnRows('left'); | |
973 | - this.rightFixedColumnRows = this.makeColumnRows('right'); | |
981 | + this.columnRows = this.makeColumnRows(false, colsWithId); | |
982 | + this.leftFixedColumnRows = this.makeColumnRows('left', colsWithId); | |
983 | + this.rightFixedColumnRows = this.makeColumnRows('right', colsWithId); | |
974 | 984 | this.rebuildData = this.makeDataWithSortAndFilter(); |
975 | 985 | this.handleResize(); |
976 | 986 | }, | ... | ... |
src/components/table/util.js
... | ... | @@ -78,4 +78,16 @@ const convertToRows = (columns, fixedType = false) => { |
78 | 78 | return rows; |
79 | 79 | }; |
80 | 80 | |
81 | -export {convertToRows}; | |
82 | 81 | \ No newline at end of file |
82 | +export {convertToRows}; | |
83 | + | |
84 | +const getRandomStr = function (len = 32) { | |
85 | + const $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; | |
86 | + const maxPos = $chars.length; | |
87 | + let str = ''; | |
88 | + for (let i = 0; i < len; i++) { | |
89 | + str += $chars.charAt(Math.floor(Math.random() * maxPos)); | |
90 | + } | |
91 | + return str; | |
92 | +}; | |
93 | + | |
94 | +export {getRandomStr}; | |
83 | 95 | \ No newline at end of file | ... | ... |