Commit 8744e122ee7ef851b2f9d231c8cbd45257fb20e7
Committed by
GitHub
Merge pull request #2 from huanghong1125/iss3124
Iss3124
Showing
4 changed files
with
156 additions
and
28 deletions
Show diff stats
examples/routers/table.vue
@@ -5,7 +5,12 @@ | @@ -5,7 +5,12 @@ | ||
5 | <Button @click="handleClearData">Clear Data</Button> | 5 | <Button @click="handleClearData">Clear Data</Button> |
6 | <Button @click="handleSelectAll(true)">Set all selected</Button> | 6 | <Button @click="handleSelectAll(true)">Set all selected</Button> |
7 | <Button @click="handleSelectAll(false)">Cancel all selected</Button> | 7 | <Button @click="handleSelectAll(false)">Cancel all selected</Button> |
8 | - | 8 | + <div style='margin:20px 0px'> |
9 | + <Table border :columns="columns2" :data="data3"></Table> | ||
10 | + </div> | ||
11 | + <div style='margin:20px 0px'> | ||
12 | + <Table :height='200' border :columns="columns2" :data="data3"></Table> | ||
13 | + </div> | ||
9 | <div style='margin:20px 0px;'> | 14 | <div style='margin:20px 0px;'> |
10 | <Table :data="tableData1" :columns="tableColumns1" :height='500' stripe size='small'></Table> | 15 | <Table :data="tableData1" :columns="tableColumns1" :height='500' stripe size='small'></Table> |
11 | <div style="margin: 10px;overflow: hidden"> | 16 | <div style="margin: 10px;overflow: hidden"> |
@@ -14,6 +19,7 @@ | @@ -14,6 +19,7 @@ | ||
14 | </div> | 19 | </div> |
15 | </div> | 20 | </div> |
16 | </div> | 21 | </div> |
22 | + | ||
17 | </div> | 23 | </div> |
18 | </template> | 24 | </template> |
19 | <script> | 25 | <script> |
@@ -49,6 +55,95 @@ | @@ -49,6 +55,95 @@ | ||
49 | data1: [ | 55 | data1: [ |
50 | 56 | ||
51 | ], | 57 | ], |
58 | + columns2: [ | ||
59 | + { | ||
60 | + title: 'Name', | ||
61 | + key: 'name', | ||
62 | + width: 100, | ||
63 | + fixed: 'left' | ||
64 | + }, | ||
65 | + { | ||
66 | + title: 'Age', | ||
67 | + key: 'age', | ||
68 | + width: 100 | ||
69 | + }, | ||
70 | + { | ||
71 | + title: 'Province', | ||
72 | + key: 'province', | ||
73 | + width: 100 | ||
74 | + }, | ||
75 | + { | ||
76 | + title: 'City', | ||
77 | + key: 'city', | ||
78 | + width: 100 | ||
79 | + }, | ||
80 | + { | ||
81 | + title: 'Address', | ||
82 | + key: 'address', | ||
83 | + width: 200 | ||
84 | + }, | ||
85 | + { | ||
86 | + title: 'Postcode', | ||
87 | + key: 'zip', | ||
88 | + width: 100 | ||
89 | + }, | ||
90 | + { | ||
91 | + title: 'Action', | ||
92 | + key: 'action', | ||
93 | + fixed: 'right', | ||
94 | + width: 120, | ||
95 | + render: (h, params) => { | ||
96 | + return h('div', [ | ||
97 | + h('Button', { | ||
98 | + props: { | ||
99 | + type: 'text', | ||
100 | + size: 'small' | ||
101 | + } | ||
102 | + }, 'View'), | ||
103 | + h('Button', { | ||
104 | + props: { | ||
105 | + type: 'text', | ||
106 | + size: 'small' | ||
107 | + } | ||
108 | + }, 'Edit') | ||
109 | + ]); | ||
110 | + } | ||
111 | + } | ||
112 | + ], | ||
113 | + data3: [ | ||
114 | + { | ||
115 | + name: 'John Brown', | ||
116 | + age: 18, | ||
117 | + address: 'New York No. 1 Lake Park', | ||
118 | + province: 'America', | ||
119 | + city: 'New York', | ||
120 | + zip: 100000 | ||
121 | + }, | ||
122 | + { | ||
123 | + name: 'Jim Green', | ||
124 | + age: 24, | ||
125 | + address: 'Washington, D.C. No. 1 Lake Park', | ||
126 | + province: 'America', | ||
127 | + city: 'Washington, D.C.', | ||
128 | + zip: 100000 | ||
129 | + }, | ||
130 | + { | ||
131 | + name: 'Joe Black', | ||
132 | + age: 30, | ||
133 | + address: 'Sydney No. 1 Lake Park', | ||
134 | + province: 'Australian', | ||
135 | + city: 'Sydney', | ||
136 | + zip: 100000 | ||
137 | + }, | ||
138 | + { | ||
139 | + name: 'Jon Snow', | ||
140 | + age: 26, | ||
141 | + address: 'Ottawa No. 2 Lake Park', | ||
142 | + province: 'Canada', | ||
143 | + city: 'Ottawa', | ||
144 | + zip: 100000 | ||
145 | + } | ||
146 | + ], | ||
52 | 147 | ||
53 | tableData1: [], | 148 | tableData1: [], |
54 | tableColumns1: [ | 149 | tableColumns1: [ |
src/components/table/mixin.js
@@ -31,7 +31,7 @@ export default { | @@ -31,7 +31,7 @@ export default { | ||
31 | width += scrollBarWidth; | 31 | width += scrollBarWidth; |
32 | } | 32 | } |
33 | // when fixed type,reset first right fixed column's width | 33 | // when fixed type,reset first right fixed column's width |
34 | - if (this.fixed === 'right') { | 34 | + if (this.fixed === 'right' && top ) { |
35 | const firstFixedIndex = this.columns.findIndex((col) => col.fixed === 'right'); | 35 | const firstFixedIndex = this.columns.findIndex((col) => col.fixed === 'right'); |
36 | if (firstFixedIndex === index) { | 36 | if (firstFixedIndex === index) { |
37 | let scrollBarWidth = this.$parent.scrollBarWidth; | 37 | let scrollBarWidth = this.$parent.scrollBarWidth; |
src/components/table/table.vue
@@ -23,12 +23,12 @@ | @@ -23,12 +23,12 @@ | ||
23 | :obj-data="objData"></table-body> | 23 | :obj-data="objData"></table-body> |
24 | </div> | 24 | </div> |
25 | <div | 25 | <div |
26 | - :class="[prefixCls + '-tip']" | 26 | + :class="[prefixCls + '-tip']" :style="bodyStyle" @scroll="handleBodyScroll" |
27 | v-show="((!!localeNoDataText && (!data || data.length === 0)) || (!!localeNoFilteredDataText && (!rebuildData || rebuildData.length === 0)))"> | 27 | v-show="((!!localeNoDataText && (!data || data.length === 0)) || (!!localeNoFilteredDataText && (!rebuildData || rebuildData.length === 0)))"> |
28 | <table cellspacing="0" cellpadding="0" border="0"> | 28 | <table cellspacing="0" cellpadding="0" border="0"> |
29 | <tbody> | 29 | <tbody> |
30 | <tr> | 30 | <tr> |
31 | - <td :style="{ 'height': bodyStyle.height }"> | 31 | + <td :style="{'height':bodyStyle.height,'width':`${this.headerWidth}px`}"> |
32 | <span v-html="localeNoDataText" v-if="!data || data.length === 0"></span> | 32 | <span v-html="localeNoDataText" v-if="!data || data.length === 0"></span> |
33 | <span v-html="localeNoFilteredDataText" v-else></span> | 33 | <span v-html="localeNoFilteredDataText" v-else></span> |
34 | </td> | 34 | </td> |
@@ -188,6 +188,8 @@ | @@ -188,6 +188,8 @@ | ||
188 | currentContext: this.context, | 188 | currentContext: this.context, |
189 | cloneData: deepCopy(this.data), // when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data | 189 | cloneData: deepCopy(this.data), // when Cell has a button to delete row data, clickCurrentRow will throw an error, so clone a data |
190 | showVerticalScrollBar:false, | 190 | showVerticalScrollBar:false, |
191 | + showHorizontalScrollBar:false, | ||
192 | + headerWidth:0 | ||
191 | }; | 193 | }; |
192 | }, | 194 | }, |
193 | computed: { | 195 | computed: { |
@@ -253,7 +255,7 @@ | @@ -253,7 +255,7 @@ | ||
253 | if (this.bodyHeight > this.bodyRealHeight) { | 255 | if (this.bodyHeight > this.bodyRealHeight) { |
254 | width = this.tableWidth; | 256 | width = this.tableWidth; |
255 | } else { | 257 | } else { |
256 | - width = this.tableWidth - this.scrollBarWidth; | 258 | + width = this.tableWidth - (this.showVerticalScrollBar?this.scrollBarWidth:0); |
257 | } | 259 | } |
258 | } | 260 | } |
259 | // const width = this.bodyHeight === 0 ? this.tableWidth : this.tableWidth - this.scrollBarWidth; | 261 | // const width = this.bodyHeight === 0 ? this.tableWidth : this.tableWidth - this.scrollBarWidth; |
@@ -276,8 +278,9 @@ | @@ -276,8 +278,9 @@ | ||
276 | this.rightFixedColumns.forEach((col) => { | 278 | this.rightFixedColumns.forEach((col) => { |
277 | if (col.fixed && col.fixed === 'right') width += col._width; | 279 | if (col.fixed && col.fixed === 'right') width += col._width; |
278 | }); | 280 | }); |
279 | - width += this.scrollBarWidth; | 281 | + //width += this.scrollBarWidth; |
280 | style.width = `${width}px`; | 282 | style.width = `${width}px`; |
283 | + style.right = `${this.showVerticalScrollBar?this.scrollBarWidth:0}px`; | ||
281 | return style; | 284 | return style; |
282 | }, | 285 | }, |
283 | bodyStyle () { | 286 | bodyStyle () { |
@@ -292,11 +295,11 @@ | @@ -292,11 +295,11 @@ | ||
292 | fixedBodyStyle () { | 295 | fixedBodyStyle () { |
293 | let style = {}; | 296 | let style = {}; |
294 | if (this.bodyHeight !== 0) { | 297 | if (this.bodyHeight !== 0) { |
295 | - let height = this.bodyHeight + this.scrollBarWidth - 1; | 298 | + let height = this.bodyHeight + (!this.showHorizontalScrollBar?this.scrollBarWidth:0) - 1; |
296 | 299 | ||
297 | // #2102 ้๏ผๅฆๆ Table ๆฒกๆ่ฎพ็ฝฎ width๏ผ่ๆฏ้ๆ็ถ็บง็ width๏ผๅบๅฎๅไนๅบ่ฏฅไธๅ ๅซๆปๅจๆก้ซๅบฆ๏ผๆไปฅ่ฟ้็ดๆฅ่ฎก็ฎ่กจๆ ผๅฎฝๅบฆ | 300 | // #2102 ้๏ผๅฆๆ Table ๆฒกๆ่ฎพ็ฝฎ width๏ผ่ๆฏ้ๆ็ถ็บง็ width๏ผๅบๅฎๅไนๅบ่ฏฅไธๅ ๅซๆปๅจๆก้ซๅบฆ๏ผๆไปฅ่ฟ้็ดๆฅ่ฎก็ฎ่กจๆ ผๅฎฝๅบฆ |
298 | const tableWidth = parseInt(getStyle(this.$el, 'width')) - 1; | 301 | const tableWidth = parseInt(getStyle(this.$el, 'width')) - 1; |
299 | - if ((this.width && this.width < this.tableWidth) || tableWidth < this.tableWidth){ | 302 | + if ((this.width && this.width < this.tableWidth) || tableWidth < this.tableWidth+(this.showVerticalScrollBar?this.scrollBarWidth:0)){ |
300 | height = this.bodyHeight; | 303 | height = this.bodyHeight; |
301 | } | 304 | } |
302 | // style.height = this.scrollBarWidth > 0 ? `${this.bodyHeight}px` : `${this.bodyHeight - 1}px`; | 305 | // style.height = this.scrollBarWidth > 0 ? `${this.bodyHeight}px` : `${this.bodyHeight - 1}px`; |
@@ -348,7 +351,13 @@ | @@ -348,7 +351,13 @@ | ||
348 | this.tableWidth = parseInt(getStyle(this.$el, 'width')) - 1; | 351 | this.tableWidth = parseInt(getStyle(this.$el, 'width')) - 1; |
349 | } | 352 | } |
350 | this.columnsWidth = {}; | 353 | this.columnsWidth = {}; |
351 | - if (!this.$refs.tbody) return; | 354 | + this.$nextTick(()=>{ |
355 | + this.headerWidth = this.$refs.header.childNodes[0].offsetWidth; | ||
356 | + if (!this.$refs.tbody) { | ||
357 | + this.showVerticalScrollBar = false; | ||
358 | + return; | ||
359 | + } | ||
360 | + }); | ||
352 | this.$nextTick(() => { | 361 | this.$nextTick(() => { |
353 | let columnsWidth = {}; | 362 | let columnsWidth = {}; |
354 | let autoWidthIndex = -1; | 363 | let autoWidthIndex = -1; |
@@ -358,7 +367,6 @@ | @@ -358,7 +367,6 @@ | ||
358 | const $tr = this.$refs.tbody.$el.querySelectorAll('tbody tr'); | 367 | const $tr = this.$refs.tbody.$el.querySelectorAll('tbody tr'); |
359 | if ($tr.length === 0) return; | 368 | if ($tr.length === 0) return; |
360 | const $td = $tr[0].children; | 369 | const $td = $tr[0].children; |
361 | - | ||
362 | for (let i = 0; i < $td.length; i++) { // can not use forEach in Firefox | 370 | for (let i = 0; i < $td.length; i++) { // can not use forEach in Firefox |
363 | const column = this.cloneColumns[i]; | 371 | const column = this.cloneColumns[i]; |
364 | 372 | ||
@@ -375,23 +383,36 @@ | @@ -375,23 +383,36 @@ | ||
375 | }; | 383 | }; |
376 | } | 384 | } |
377 | this.columnsWidth = columnsWidth; | 385 | this.columnsWidth = columnsWidth; |
378 | - this.fixedHeader(); | ||
379 | - | ||
380 | - if (this.$refs.tbody) { | ||
381 | - let bodyContentEl = this.$refs.tbody.$el; | ||
382 | - let bodyEl = bodyContentEl.parentElement; | ||
383 | - bodyEl.className = ''; | ||
384 | - this.$nextTick(() => { bodyEl.className = this.prefixCls + '-body'; }); | ||
385 | - let bodyContentHeight = bodyContentEl.offsetHeight; | ||
386 | - let bodyContentWidth = bodyContentEl.offsetWidth; | ||
387 | - let bodyWidth = bodyEl.offsetWidth; | ||
388 | - let bodyHeight = bodyEl.offsetHeight; | ||
389 | - let scrollBarWidth = 0; | ||
390 | - if (bodyWidth < bodyContentWidth) { | ||
391 | - scrollBarWidth = this.scrollBarWidth; | 386 | + this.$nextTick(()=>{ |
387 | + this.fixedHeader(); | ||
388 | + if (this.$refs.tbody) { | ||
389 | + let bodyContentEl = this.$refs.tbody.$el; | ||
390 | + let bodyEl = bodyContentEl.parentElement; | ||
391 | + let bodyContentHeight = bodyContentEl.offsetHeight; | ||
392 | + let bodyContentWidth = bodyContentEl.offsetWidth; | ||
393 | + let bodyWidth = bodyEl.offsetWidth; | ||
394 | + let bodyHeight = bodyEl.offsetHeight; | ||
395 | + let scrollBarWidth = 0; | ||
396 | + if (bodyWidth < bodyContentWidth + (bodyHeight<bodyContentHeight?this.scrollBarWidth : 0)) { | ||
397 | + scrollBarWidth = this.scrollBarWidth; | ||
398 | + } | ||
399 | + | ||
400 | + this.showVerticalScrollBar = this.bodyHeight? bodyHeight - scrollBarWidth < bodyContentHeight : false; | ||
401 | + this.showHorizontalScrollBar = bodyWidth < bodyContentWidth + (this.showVerticalScrollBar?this.scrollBarWidth:0); | ||
402 | + | ||
403 | + if(this.showVerticalScrollBar){ | ||
404 | + bodyEl.classList.add(this.prefixCls +'-overflowY'); | ||
405 | + }else{ | ||
406 | + bodyEl.classList.remove(this.prefixCls +'-overflowY'); | ||
407 | + } | ||
408 | + if(this.showHorizontalScrollBar){ | ||
409 | + bodyEl.classList.add(this.prefixCls +'-overflowX'); | ||
410 | + }else{ | ||
411 | + bodyEl.classList.remove(this.prefixCls +'-overflowX'); | ||
412 | + } | ||
413 | + | ||
392 | } | 414 | } |
393 | - this.showVerticalScrollBar = this.bodyHeight? bodyHeight - scrollBarWidth < bodyContentHeight : false; | ||
394 | - } | 415 | + }); |
395 | } | 416 | } |
396 | }); | 417 | }); |
397 | // get table real height,for fixed when set height prop,but height < table's height,show scrollBarWidth | 418 | // get table real height,for fixed when set height prop,but height < table's height,show scrollBarWidth |
src/styles/components/table.less
@@ -71,7 +71,19 @@ | @@ -71,7 +71,19 @@ | ||
71 | overflow: hidden; | 71 | overflow: hidden; |
72 | } | 72 | } |
73 | &-body{ | 73 | &-body{ |
74 | - overflow: auto; | 74 | + //overflow: auto; |
75 | + //position: relative; | ||
76 | + | ||
77 | + } | ||
78 | + &-overflowX{ | ||
79 | + overflow-x: scroll; | ||
80 | + } | ||
81 | + &-overflowY{ | ||
82 | + overflow-y: scroll; | ||
83 | + } | ||
84 | + &-tip{ | ||
85 | + overflow-x: auto; | ||
86 | + overflow-y: hidden; | ||
75 | //position: relative; | 87 | //position: relative; |
76 | } | 88 | } |
77 | 89 | ||
@@ -273,7 +285,7 @@ | @@ -273,7 +285,7 @@ | ||
273 | box-shadow: -2px 0 6px -2px rgba(0, 0, 0, 0.2); | 285 | box-shadow: -2px 0 6px -2px rgba(0, 0, 0, 0.2); |
274 | } | 286 | } |
275 | &-fixed-header{ | 287 | &-fixed-header{ |
276 | - overflow: hidden; | 288 | + overflow: visible; |
277 | &-with-empty{ | 289 | &-with-empty{ |
278 | .@{table-prefix-cls}-hidden{ | 290 | .@{table-prefix-cls}-hidden{ |
279 | .@{table-prefix-cls}-sort{ | 291 | .@{table-prefix-cls}-sort{ |