Skip to content

Commit 969970d

Browse files
committed
add document for default sort
1 parent 79aa0ca commit 969970d

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

docs/en-us/sort.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,41 @@
22

33
`sort` feature of `vue-data-tables` is based on the [customize sort](http://element.eleme.io/#/en-US/component/table#sorting) of `el-table`. Setting `sortable` prop of `el-table-column` to `custom` can enable customize sort of the column.
44

5-
> PS, Setting `sortable` to `true` can also work, but `vue-data-table` and embedded `el-table` both sort the data, which may cause performance downgrade.
5+
> PS: Setting `sortable` to `true` can also work, but `vue-data-table` and embedded `el-table` both sort the data, which may cause performance downgrade.
66
7-
`el-table` accepts `default-sort` prop to set default sort column and order. `vue-data-tables` can pass any props to embedded `el-table` by prop [table-props](en-us/basic.md?id=pass-props-to-the-embedded-el-table), so we can define `vue-data-tables`'s default sort by `:table-props='{ defaultSort: VALUE }'`.
7+
```html
8+
/*vue*/
9+
<desc>
10+
* `sortable="custom"` 很重要
11+
* `tableProps.defaultSort` 定义了默认的排序列
12+
</desc>
13+
<template>
14+
<data-tables
15+
:data='data'
16+
>
17+
<el-table-column v-for="title in titles"
18+
:prop="title.prop"
19+
:label="title.label"
20+
:key="title.label"
21+
sortable="custom">
22+
</el-table-column>
23+
</data-tables>
24+
</template>
25+
26+
<script>
27+
export default {
28+
data() {
29+
return {
30+
data,
31+
titles,
32+
}
33+
}
34+
}
35+
</script>
36+
```
37+
38+
## Default sort
39+
As mentioned in [previous section](en-us/basic.md?id=pass-props-to-the-embedded-el-table), `el-table` accepts `default-sort` prop to set default sort column and order. `vue-data-tables` can pass any props to embedded `el-table` by prop [table-props](en-us/basic.md?id=pass-props-to-the-embedded-el-table), so we can define `vue-data-tables`'s default sort by `:table-props='{ defaultSort: VALUE }'`.
840

941
```html
1042
/*vue*/

docs/zh-cn/sort.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,41 @@
44

55
> 注意虽然把 `sortable` 属性为 `true` 也可以工作,但是此时 `vue-data-table` 和内置的 `el-table` 都会对数据进行排序,会影响表格的性能。
66
7-
我们可以通过 `el-table``default-sort` 属性来设置默认的排序列和方向。对于 `vue-data-tables` 来说所有的内置 `el-table` 的属性,都可以通过 [table-props](zh-cn/basic.md?id=传递-prop-给内置的-el-table) 来传递,所以我们可以通过 `:table-props='{ defaultSort: VALUE }'`, 来为 `vue-data-tables` 定义默认排序。
7+
8+
```html
9+
/*vue*/
10+
<desc>
11+
* `sortable="custom"` 很重要
12+
* `tableProps.defaultSort` 定义了默认的排序列
13+
</desc>
14+
<template>
15+
<data-tables
16+
:data='data'
17+
>
18+
<el-table-column v-for="title in titles"
19+
:prop="title.prop"
20+
:label="title.label"
21+
:key="title.label"
22+
sortable="custom">
23+
</el-table-column>
24+
</data-tables>
25+
</template>
26+
27+
<script>
28+
export default {
29+
data() {
30+
return {
31+
data,
32+
titles,
33+
}
34+
}
35+
}
36+
</script>
37+
```
38+
39+
## 默认排序
40+
41+
[前文](zh-cn/basic.md?id=传递-prop-给内置的-el-table)提到的,我们可以通过 `el-table``default-sort` 属性来设置默认的排序列和方向。对于 `vue-data-tables` 来说所有的内置 `el-table` 的属性,都可以通过 [table-props](zh-cn/basic.md?id=传递-prop-给内置的-el-table) 来传递,所以我们可以通过 `:table-props='{ defaultSort: VALUE }'`, 来为 `vue-data-tables` 定义默认排序。
842

943
```html
1044
/*vue*/

0 commit comments

Comments
 (0)