Commit c1e965c37166cb3a9d0e8bd17124a2e66beaaf31
1 parent
3f14387d
fixed-head
Showing
4 changed files
with
37 additions
and
27 deletions
Show diff stats
examples/routers/table.vue
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | <br><br><br><br><br> | 3 | <br><br><br><br><br> |
4 | <Table border :columns="columns1" height="500" :data="data1"></Table> | 4 | <Table border :columns="columns1" height="500" :data="data1"></Table> |
5 | <br><br><br><br><br> | 5 | <br><br><br><br><br> |
6 | - <!--<Table width="550" height="200" border :columns="columns2" :data="data4"></Table>--> | 6 | + <Table width="550" height="200" border :columns="columns2" :data="data4"></Table> |
7 | <br><br><br><br><br> | 7 | <br><br><br><br><br> |
8 | </div> | 8 | </div> |
9 | </template> | 9 | </template> |
@@ -84,8 +84,7 @@ | @@ -84,8 +84,7 @@ | ||
84 | key: 'gender', | 84 | key: 'gender', |
85 | align: 'center', | 85 | align: 'center', |
86 | width: 200, | 86 | width: 200, |
87 | - fixed: 'right', | ||
88 | - // fixed: 'left' | 87 | + fixed: 'right' |
89 | } | 88 | } |
90 | ], | 89 | ], |
91 | columns2: [ | 90 | columns2: [ |
src/components/table/table-head.vue
@@ -87,7 +87,8 @@ | @@ -87,7 +87,8 @@ | ||
87 | type: [Boolean, String], | 87 | type: [Boolean, String], |
88 | default: false | 88 | default: false |
89 | }, | 89 | }, |
90 | - columnRows: Array | 90 | + columnRows: Array, |
91 | + fixedColumnRows: Array | ||
91 | }, | 92 | }, |
92 | computed: { | 93 | computed: { |
93 | styles () { | 94 | styles () { |
@@ -116,7 +117,11 @@ | @@ -116,7 +117,11 @@ | ||
116 | }, | 117 | }, |
117 | headRows () { | 118 | headRows () { |
118 | const isGroup = this.columnRows.length > 1; | 119 | const isGroup = this.columnRows.length > 1; |
119 | - return isGroup ? this.columnRows : [this.columns]; | 120 | + if (isGroup) { |
121 | + return this.fixed ? this.fixedColumnRows : this.columnRows; | ||
122 | + } else { | ||
123 | + return [this.columns]; | ||
124 | + } | ||
120 | } | 125 | } |
121 | }, | 126 | }, |
122 | methods: { | 127 | methods: { |
src/components/table/table.vue
@@ -45,6 +45,7 @@ | @@ -45,6 +45,7 @@ | ||
45 | :styleObject="fixedTableStyle" | 45 | :styleObject="fixedTableStyle" |
46 | :columns="leftFixedColumns" | 46 | :columns="leftFixedColumns" |
47 | :column-rows="columnRows" | 47 | :column-rows="columnRows" |
48 | + :fixed-column-rows="leftFixedColumnRows" | ||
48 | :obj-data="objData" | 49 | :obj-data="objData" |
49 | :columns-width="columnsWidth" | 50 | :columns-width="columnsWidth" |
50 | :data="rebuildData"></table-head> | 51 | :data="rebuildData"></table-head> |
@@ -68,6 +69,7 @@ | @@ -68,6 +69,7 @@ | ||
68 | :styleObject="fixedRightTableStyle" | 69 | :styleObject="fixedRightTableStyle" |
69 | :columns="rightFixedColumns" | 70 | :columns="rightFixedColumns" |
70 | :column-rows="columnRows" | 71 | :column-rows="columnRows" |
72 | + :fixed-column-rows="rightFixedColumnRows" | ||
71 | :obj-data="objData" | 73 | :obj-data="objData" |
72 | :columns-width="columnsWidth" | 74 | :columns-width="columnsWidth" |
73 | :data="rebuildData"></table-head> | 75 | :data="rebuildData"></table-head> |
@@ -184,7 +186,9 @@ | @@ -184,7 +186,9 @@ | ||
184 | objData: this.makeObjData(), // checkbox or highlight-row | 186 | objData: this.makeObjData(), // checkbox or highlight-row |
185 | rebuildData: [], // for sort or filter | 187 | rebuildData: [], // for sort or filter |
186 | cloneColumns: this.makeColumns(), | 188 | cloneColumns: this.makeColumns(), |
187 | - columnRows: this.makeColumnRows(), | 189 | + columnRows: this.makeColumnRows(false), |
190 | + leftFixedColumnRows: this.makeColumnRows('left'), | ||
191 | + rightFixedColumnRows: this.makeColumnRows('right'), | ||
188 | allColumns: getAllColumns(this.columns), // for multiple table-head, get columns that have no children | 192 | allColumns: getAllColumns(this.columns), // for multiple table-head, get columns that have no children |
189 | showSlotHeader: true, | 193 | showSlotHeader: true, |
190 | showSlotFooter: true, | 194 | showSlotFooter: true, |
@@ -779,8 +783,8 @@ | @@ -779,8 +783,8 @@ | ||
779 | return left.concat(center).concat(right); | 783 | return left.concat(center).concat(right); |
780 | }, | 784 | }, |
781 | // create a multiple table-head | 785 | // create a multiple table-head |
782 | - makeColumnRows () { | ||
783 | - return convertToRows(this.columns); | 786 | + makeColumnRows (fixedType) { |
787 | + return convertToRows(this.columns, fixedType); | ||
784 | }, | 788 | }, |
785 | exportCsv (params) { | 789 | exportCsv (params) { |
786 | if (params.filename) { | 790 | if (params.filename) { |
@@ -858,7 +862,9 @@ | @@ -858,7 +862,9 @@ | ||
858 | // todo 这里有性能问题,可能是左右固定计算属性影响的 | 862 | // todo 这里有性能问题,可能是左右固定计算属性影响的 |
859 | this.allColumns = getAllColumns(this.columns); | 863 | this.allColumns = getAllColumns(this.columns); |
860 | this.cloneColumns = this.makeColumns(); | 864 | this.cloneColumns = this.makeColumns(); |
861 | - this.columnRows = this.makeColumnRows(); | 865 | + this.columnRows = this.makeColumnRows(false); |
866 | + this.leftFixedColumnRows = this.makeColumnRows('left'); | ||
867 | + this.rightFixedColumnRows = this.makeColumnRows('right'); | ||
862 | this.rebuildData = this.makeDataWithSortAndFilter(); | 868 | this.rebuildData = this.makeDataWithSortAndFilter(); |
863 | this.handleResize(); | 869 | this.handleResize(); |
864 | }, | 870 | }, |
src/components/table/util.js
1 | import { deepCopy } from '../../utils/assist'; | 1 | import { deepCopy } from '../../utils/assist'; |
2 | 2 | ||
3 | +const convertColumnOrder = (columns, fixedType) => { | ||
4 | + let list = []; | ||
5 | + let other = []; | ||
6 | + columns.forEach((col) => { | ||
7 | + if (col.fixed && col.fixed === fixedType) { | ||
8 | + list.push(col); | ||
9 | + } else { | ||
10 | + other.push(col); | ||
11 | + } | ||
12 | + }); | ||
13 | + return list.concat(other); | ||
14 | +}; | ||
15 | + | ||
16 | +export {convertColumnOrder}; | ||
17 | + | ||
3 | // set forTableHead to true when convertToRows, false in normal cases like table.vue | 18 | // set forTableHead to true when convertToRows, false in normal cases like table.vue |
4 | const getAllColumns = (cols, forTableHead = false) => { | 19 | const getAllColumns = (cols, forTableHead = false) => { |
5 | const columns = deepCopy(cols); | 20 | const columns = deepCopy(cols); |
@@ -17,8 +32,8 @@ const getAllColumns = (cols, forTableHead = false) => { | @@ -17,8 +32,8 @@ const getAllColumns = (cols, forTableHead = false) => { | ||
17 | 32 | ||
18 | export {getAllColumns}; | 33 | export {getAllColumns}; |
19 | 34 | ||
20 | -const convertToRows = (columns) => { | ||
21 | - const originColumns = deepCopy(columns); | 35 | +const convertToRows = (columns, fixedType = false) => { |
36 | + const originColumns = fixedType ? fixedType === 'left' ? deepCopy(convertColumnOrder(columns, 'left')) : deepCopy(convertColumnOrder(columns, 'right')) : deepCopy(columns); | ||
22 | let maxLevel = 1; | 37 | let maxLevel = 1; |
23 | const traverse = (column, parent) => { | 38 | const traverse = (column, parent) => { |
24 | if (parent) { | 39 | if (parent) { |
@@ -63,19 +78,4 @@ const convertToRows = (columns) => { | @@ -63,19 +78,4 @@ const convertToRows = (columns) => { | ||
63 | return rows; | 78 | return rows; |
64 | }; | 79 | }; |
65 | 80 | ||
66 | -export {convertToRows}; | ||
67 | - | ||
68 | -const convertColumnOrder = (columns, FixedType) => { | ||
69 | - let list = []; | ||
70 | - let other = []; | ||
71 | - columns.forEach((col) => { | ||
72 | - if (col.fixed && col.fixed === FixedType) { | ||
73 | - list.push(col); | ||
74 | - } else { | ||
75 | - other.push(col); | ||
76 | - } | ||
77 | - }); | ||
78 | - return list.concat(other); | ||
79 | -}; | ||
80 | - | ||
81 | -export {convertColumnOrder}; | ||
82 | \ No newline at end of file | 81 | \ No newline at end of file |
82 | +export {convertToRows}; | ||
83 | \ No newline at end of file | 83 | \ No newline at end of file |