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,6 +34,7 @@ | ||
34 | <span :class="[prefixCls + '-filter']"> | 34 | <span :class="[prefixCls + '-filter']"> |
35 | <i class="ivu-icon ivu-icon-funnel" :class="{on: getColumn(rowIndex, index)._isFiltered}"></i> | 35 | <i class="ivu-icon ivu-icon-funnel" :class="{on: getColumn(rowIndex, index)._isFiltered}"></i> |
36 | </span> | 36 | </span> |
37 | + | ||
37 | <div slot="content" :class="[prefixCls + '-filter-list']" v-if="getColumn(rowIndex, index)._filterMultiple"> | 38 | <div slot="content" :class="[prefixCls + '-filter-list']" v-if="getColumn(rowIndex, index)._filterMultiple"> |
38 | <div :class="[prefixCls + '-filter-list-item']"> | 39 | <div :class="[prefixCls + '-filter-list-item']"> |
39 | <checkbox-group v-model="getColumn(rowIndex, index)._filterChecked"> | 40 | <checkbox-group v-model="getColumn(rowIndex, index)._filterChecked"> |
@@ -133,8 +134,8 @@ | @@ -133,8 +134,8 @@ | ||
133 | }, | 134 | }, |
134 | scrollBarCellClass(){ | 135 | scrollBarCellClass(){ |
135 | let hasRightFixed = false; | 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 | if(this.headRows[i][j].fixed === 'right') { | 139 | if(this.headRows[i][j].fixed === 'right') { |
139 | hasRightFixed=true; | 140 | hasRightFixed=true; |
140 | break; | 141 | break; |
@@ -205,7 +206,13 @@ | @@ -205,7 +206,13 @@ | ||
205 | // 因为表头嵌套不是深拷贝,所以没有 _ 开头的方法,在 isGroup 下用此列 | 206 | // 因为表头嵌套不是深拷贝,所以没有 _ 开头的方法,在 isGroup 下用此列 |
206 | getColumn (rowIndex, index) { | 207 | getColumn (rowIndex, index) { |
207 | const isGroup = this.columnRows.length > 1; | 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,7 +103,7 @@ | ||
103 | import ExportCsv from './export-csv'; | 103 | import ExportCsv from './export-csv'; |
104 | import Locale from '../../mixins/locale'; | 104 | import Locale from '../../mixins/locale'; |
105 | import elementResizeDetectorMaker from 'element-resize-detector'; | 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 | const prefixCls = 'ivu-table'; | 108 | const prefixCls = 'ivu-table'; |
109 | 109 | ||
@@ -178,6 +178,7 @@ | @@ -178,6 +178,7 @@ | ||
178 | } | 178 | } |
179 | }, | 179 | }, |
180 | data () { | 180 | data () { |
181 | + const colsWithId = this.makeColumnsId(this.columns); | ||
181 | return { | 182 | return { |
182 | ready: false, | 183 | ready: false, |
183 | tableWidth: 0, | 184 | tableWidth: 0, |
@@ -186,13 +187,13 @@ | @@ -186,13 +187,13 @@ | ||
186 | compiledUids: [], | 187 | compiledUids: [], |
187 | objData: this.makeObjData(), // checkbox or highlight-row | 188 | objData: this.makeObjData(), // checkbox or highlight-row |
188 | rebuildData: [], // for sort or filter | 189 | rebuildData: [], // for sort or filter |
189 | - cloneColumns: this.makeColumns(), | 190 | + cloneColumns: this.makeColumns(colsWithId), |
190 | minWidthColumns:[], | 191 | minWidthColumns:[], |
191 | maxWidthColumns:[], | 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 | showSlotHeader: true, | 197 | showSlotHeader: true, |
197 | showSlotFooter: true, | 198 | showSlotFooter: true, |
198 | bodyHeight: 0, | 199 | bodyHeight: 0, |
@@ -828,9 +829,17 @@ | @@ -828,9 +829,17 @@ | ||
828 | }); | 829 | }); |
829 | return data; | 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 | // 在 data 时,this.allColumns 暂时为 undefined | 841 | // 在 data 时,this.allColumns 暂时为 undefined |
833 | - let columns = deepCopy(getAllColumns(this.columns)); | 842 | + let columns = deepCopy(getAllColumns(cols)); |
834 | let left = []; | 843 | let left = []; |
835 | let right = []; | 844 | let right = []; |
836 | let center = []; | 845 | let center = []; |
@@ -869,8 +878,8 @@ | @@ -869,8 +878,8 @@ | ||
869 | return left.concat(center).concat(right); | 878 | return left.concat(center).concat(right); |
870 | }, | 879 | }, |
871 | // create a multiple table-head | 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 | setMinMaxColumnRows (){ | 884 | setMinMaxColumnRows (){ |
876 | let minWidthColumns=[]; | 885 | let minWidthColumns=[]; |
@@ -964,13 +973,14 @@ | @@ -964,13 +973,14 @@ | ||
964 | columns: { | 973 | columns: { |
965 | handler () { | 974 | handler () { |
966 | // todo 这里有性能问题,可能是左右固定计算属性影响的 | 975 | // todo 这里有性能问题,可能是左右固定计算属性影响的 |
967 | - this.allColumns = getAllColumns(this.columns); | 976 | + const colsWithId = this.makeColumnsId(this.columns); |
977 | + this.allColumns = getAllColumns(colsWithId); | ||
968 | this.cloneColumns = this.makeColumns(); | 978 | this.cloneColumns = this.makeColumns(); |
969 | this.setMinMaxColumnRows(); | 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 | this.rebuildData = this.makeDataWithSortAndFilter(); | 984 | this.rebuildData = this.makeDataWithSortAndFilter(); |
975 | this.handleResize(); | 985 | this.handleResize(); |
976 | }, | 986 | }, |
src/components/table/util.js
@@ -78,4 +78,16 @@ const convertToRows = (columns, fixedType = false) => { | @@ -78,4 +78,16 @@ const convertToRows = (columns, fixedType = false) => { | ||
78 | return rows; | 78 | return rows; |
79 | }; | 79 | }; |
80 | 80 | ||
81 | -export {convertToRows}; | ||
82 | \ No newline at end of file | 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 | \ No newline at end of file | 95 | \ No newline at end of file |