Skip to content

Commit baed537

Browse files
committed
表格高度示例文档
1 parent 6fe2257 commit baed537

File tree

15 files changed

+393
-44
lines changed

15 files changed

+393
-44
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
:::anchor Auto Table Height
2+
3+
:::demo When the table height is not set, the table height is auto height
4+
5+
```html
6+
<template>
7+
<ve-table :columns="columns" :table-data="tableData" />
8+
</template>
9+
10+
<script>
11+
export default {
12+
data() {
13+
return {
14+
columns: [
15+
{ field: "name", key: "a", title: "Name", align: "center" },
16+
{ field: "date", key: "b", title: "Date", align: "left" },
17+
{ field: "hobby", key: "c", title: "Hobby", align: "center" },
18+
{ field: "address", key: "d", title: "Address", align: "left" },
19+
],
20+
tableData: [],
21+
};
22+
},
23+
methods: {
24+
initTableData() {
25+
let data = [];
26+
for (let i = 0; i < 2; i++) {
27+
data.push({
28+
name: i,
29+
date: i,
30+
hobby: i,
31+
address: i,
32+
});
33+
}
34+
this.tableData = data;
35+
},
36+
},
37+
created() {
38+
this.initTableData();
39+
},
40+
};
41+
</script>
42+
```
43+
44+
:::
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
:::anchor Dynamic Table Height(calc css function)
2+
3+
:::demo 1、You can use [calc css function](<https://developer.mozilla.org/en-US/docs/Web/CSS/calc()>) to achieve table dynamic height<br>2、Try changing the browser height to see the effect
4+
5+
```html
6+
<template>
7+
<ve-table
8+
max-height="calc(100vh - 350px)"
9+
fixed-header
10+
:columns="columns"
11+
:table-data="tableData"
12+
/>
13+
</template>
14+
15+
<script>
16+
export default {
17+
data() {
18+
return {
19+
columns: [
20+
{ field: "name", key: "a", title: "Name", align: "center" },
21+
{ field: "date", key: "b", title: "Date", align: "left" },
22+
{
23+
field: "hobby",
24+
key: "c",
25+
title: "Hobby",
26+
align: "center",
27+
},
28+
{
29+
field: "address",
30+
key: "d",
31+
title: "Address",
32+
align: "left",
33+
},
34+
],
35+
tableData: [],
36+
};
37+
},
38+
methods: {
39+
initTableData() {
40+
let data = [];
41+
for (let i = 0; i < 20; i++) {
42+
data.push({
43+
name: i,
44+
date: i,
45+
hobby: i,
46+
address: i,
47+
});
48+
}
49+
this.tableData = data;
50+
},
51+
},
52+
created() {
53+
this.initTableData();
54+
},
55+
};
56+
</script>
57+
```
58+
59+
:::
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:::tip
2+
1、The table height is determined by row data by default. You can also set the max height through the `max-height` attribute<br>
3+
2、Table height can be set to a fixed value. like:`:max-height="500"`<br>
4+
3、Table height can be set to a dynamic value. like:`max-height="calc(100vh - 210px)"` or `max-height="80%"`<br>
5+
6+
:::
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
:::anchor Fixed Table Height
2+
3+
:::demo
4+
5+
```html
6+
<template>
7+
<ve-table
8+
:max-height="300"
9+
:columns="columns"
10+
:table-data="tableData"
11+
:border-around="true"
12+
:border-x="true"
13+
:border-y="true"
14+
/>
15+
</template>
16+
17+
<script>
18+
export default {
19+
data() {
20+
return {
21+
columns: [
22+
{ field: "name", key: "a", title: "Name", width: 100 },
23+
{ field: "date", key: "b", title: "Tel", width: 200 },
24+
{ field: "hobby", key: "c", title: "Hobby", width: 300 },
25+
{ field: "address", key: "d", title: "Address", width: 300 },
26+
],
27+
tableData: [],
28+
};
29+
},
30+
methods: {
31+
initTableData() {
32+
let data = [];
33+
for (let i = 0; i < 20; i++) {
34+
data.push({
35+
name: i,
36+
date: i,
37+
hobby: i,
38+
address: i,
39+
});
40+
}
41+
this.tableData = data;
42+
},
43+
},
44+
created() {
45+
this.initTableData();
46+
},
47+
};
48+
</script>
49+
```
50+
51+
:::
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<template>
2+
<div>
3+
<h2>Table Height</h2>
4+
<Explain />
5+
<AutoHeight />
6+
<FixedHeight />
7+
<CalcHeight />
8+
</div>
9+
</template>
10+
<script>
11+
import Explain from "./explain.md";
12+
import AutoHeight from "./auto-height.md";
13+
import FixedHeight from "./fixed-height.md";
14+
import CalcHeight from "./calc-height.md";
15+
16+
export default {
17+
name: "basic-main",
18+
components: {
19+
Explain,
20+
AutoHeight,
21+
FixedHeight,
22+
CalcHeight,
23+
},
24+
};
25+
</script>

examples/src/docs/en/ve-table/table-width/auto-width.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
:::anchor Auto Width
1+
:::anchor Auto Table Width
22

33
:::demo If the table width is not set, it is equivalent to `style="width:100%;"`
44

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
:::anchor 表格高度自适应
2+
3+
:::demo 当不设置表格高度时,表格高度根据内容撑开
4+
5+
```html
6+
<template>
7+
<ve-table :columns="columns" :table-data="tableData" />
8+
</template>
9+
10+
<script>
11+
export default {
12+
data() {
13+
return {
14+
columns: [
15+
{ field: "name", key: "a", title: "Name", align: "center" },
16+
{ field: "date", key: "b", title: "Date", align: "left" },
17+
{ field: "hobby", key: "c", title: "Hobby", align: "center" },
18+
{ field: "address", key: "d", title: "Address", align: "left" },
19+
],
20+
tableData: [],
21+
};
22+
},
23+
methods: {
24+
initTableData() {
25+
let data = [];
26+
for (let i = 0; i < 2; i++) {
27+
data.push({
28+
name: i,
29+
date: i,
30+
hobby: i,
31+
address: i,
32+
});
33+
}
34+
this.tableData = data;
35+
},
36+
},
37+
created() {
38+
this.initTableData();
39+
},
40+
};
41+
</script>
42+
```
43+
44+
:::
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
:::anchor 表格动态高度(calc css 函数)
2+
3+
:::demo 1、你可以使用 [calc css 函数](<https://developer.mozilla.org/en-US/docs/Web/CSS/calc()>) 实现表格动态高度<br>2、试试改变浏览器宽度查看效果
4+
5+
```html
6+
<template>
7+
<ve-table
8+
max-height="calc(100vh - 350px)"
9+
fixed-header
10+
:columns="columns"
11+
:table-data="tableData"
12+
/>
13+
</template>
14+
15+
<script>
16+
export default {
17+
data() {
18+
return {
19+
columns: [
20+
{ field: "name", key: "a", title: "Name", align: "center" },
21+
{ field: "date", key: "b", title: "Date", align: "left" },
22+
{
23+
field: "hobby",
24+
key: "c",
25+
title: "Hobby",
26+
align: "center",
27+
},
28+
{
29+
field: "address",
30+
key: "d",
31+
title: "Address",
32+
align: "left",
33+
},
34+
],
35+
tableData: [],
36+
};
37+
},
38+
methods: {
39+
initTableData() {
40+
let data = [];
41+
for (let i = 0; i < 20; i++) {
42+
data.push({
43+
name: i,
44+
date: i,
45+
hobby: i,
46+
address: i,
47+
});
48+
}
49+
this.tableData = data;
50+
},
51+
},
52+
created() {
53+
this.initTableData();
54+
},
55+
};
56+
</script>
57+
```
58+
59+
:::
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
:::tip
2-
1、表格高度可以设置固定值。如:`:max-height="500"`<br>
3-
2、表格高度可以设置动态值。如:`max-height="calc(100vh - 210px)"` 或者 `max-height="80%"`<br>
2+
1、表格高度默认由行数据决定,也可以通过 `max-height`属性设置最大高度<br>
3+
2、表格高度可以设置固定值。如:`:max-height="500"`<br>
4+
3、表格高度可以设置动态值。如:`max-height="calc(100vh - 210px)"` 或者 `max-height="80%"`<br>
45

56
:::

examples/src/docs/zh/ve-table/table-height/fixed-height.md

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
```html
66
<template>
77
<ve-table
8-
style="width:900px;height:1000px;"
8+
:max-height="300"
99
:columns="columns"
1010
:table-data="tableData"
1111
:border-around="true"
@@ -19,45 +19,31 @@
1919
data() {
2020
return {
2121
columns: [
22-
{ field: "name", key: "a", title: "Name 100px", width: 100 },
23-
{ field: "date", key: "b", title: "Tel 200px", width: 200 },
24-
{ field: "hobby", key: "c", title: "Hobby 300px", width: 300 },
25-
{ field: "address", key: "d", title: "Address 300px", width: 300 },
26-
],
27-
tableData: [
28-
{
29-
name: "John",
30-
date: "1900-05-20",
31-
hobby: "coding and coding repeat",
32-
address: "No.1 Century Avenue, Shanghai",
33-
},
34-
{
35-
name: "Dickerson",
36-
date: "1910-06-20",
37-
hobby: "coding and coding repeat",
38-
address: "No.1 Century Avenue, Beijing",
39-
},
40-
{
41-
name: "Larsen",
42-
date: "2000-07-20",
43-
hobby: "coding and coding repeat",
44-
address: "No.1 Century Avenue, Chongqing",
45-
},
46-
{
47-
name: "Geneva",
48-
date: "2010-08-20",
49-
hobby: "coding and coding repeat",
50-
address: "No.1 Century Avenue, Xiamen",
51-
},
52-
{
53-
name: "Jami",
54-
date: "2020-09-20",
55-
hobby: "coding and coding repeat",
56-
address: "No.1 Century Avenue, Shenzhen",
57-
},
22+
{ field: "name", key: "a", title: "Name", width: 100 },
23+
{ field: "date", key: "b", title: "Tel", width: 200 },
24+
{ field: "hobby", key: "c", title: "Hobby", width: 300 },
25+
{ field: "address", key: "d", title: "Address", width: 300 },
5826
],
27+
tableData: [],
5928
};
6029
},
30+
methods: {
31+
initTableData() {
32+
let data = [];
33+
for (let i = 0; i < 20; i++) {
34+
data.push({
35+
name: i,
36+
date: i,
37+
hobby: i,
38+
address: i,
39+
});
40+
}
41+
this.tableData = data;
42+
},
43+
},
44+
created() {
45+
this.initTableData();
46+
},
6147
};
6248
</script>
6349
```

0 commit comments

Comments
 (0)