naive-ui/demo/documentation/components/data-table/enUS/index.demo-entry.md

100 lines
5.8 KiB
Markdown
Raw Normal View History

2020-02-04 23:13:53 +08:00
# Data Table
<!--single-column-->
2020-02-04 22:43:40 +08:00
DataTable is used to displays rows of structured data.
## Demos
2020-01-31 17:02:33 +08:00
<n-alert type="warning" title="Caveat" style="margin-bottom: 16px;">
2020-10-22 14:30:14 +08:00
Every row data needs a unique key property, otherwise you should specify <n-text code>row-key</n-text>
2020-01-31 17:02:33 +08:00
</n-alert>
```demo
basic
2020-02-24 16:25:02 +08:00
border
2020-03-03 18:08:58 +08:00
size
2020-09-03 23:40:38 +08:00
filter-and-sorter
2020-01-10 14:43:10 +08:00
select
controlled-page
controlled-filter
controlled-sorter
2020-09-03 23:40:38 +08:00
fixed-header
fixed-header-column
ellipsis
2020-09-03 23:40:38 +08:00
render-header
custom-style
ajax-usage
```
2019-12-26 23:59:41 +08:00
## Props
2020-01-31 17:02:33 +08:00
|Name|Type|Default|Description|
|-|-|-|-|
|theme|`'light' \| 'dark' \| string`|`undefined`||
2020-10-22 14:30:14 +08:00
|data|`Array<Object>`|`[]`|Data to display.|
|columns|`Array<Column>`|required|Columns to display.|
|max-height|`number \| string`|`undefined`|The max-height of the table. If content height is larger than it, the header will be fixed at top|
|min-height|`number \| string`|`undefined`|The min-height of the table.|
2020-01-31 17:02:33 +08:00
|loading|`boolean`|`false`||
2020-10-22 14:30:14 +08:00
|scroll-x|`number \| string`|`undefined`|If columns are horizontal fixed, scroll-x need to be set|
2020-05-31 14:33:44 +08:00
|pagination|`false \| Object`|`false`|See [Pagination props](n-pagination#Props)|
|paging|`boolean`|`true`|If data-table do automatic paging. You may set it to `false` in async usage.|
2020-05-31 14:33:44 +08:00
|row-class-name|`string \| (rowData: Object, index : number) => string \| Object`|`null`||
|checked-row-keys|`Array<string \| number> \| null`|`null`|The keys of checked rows.|
2020-01-31 17:02:33 +08:00
|default-checked-row-keys|`Array<string \| number>`|`[]`||
2020-05-31 14:33:44 +08:00
|row-key|`(rowData: Object) => number \| string`|`null`|Generate the key of the row by row data (if you don't want to set the key)|
2020-02-24 16:25:02 +08:00
|bordered|`boolean`|`true`||
|single-line|`boolean`|`true`||
2020-03-17 17:17:29 +08:00
|single-column|`boolean`|`false`||
2020-03-03 12:40:05 +08:00
|size|`'small' \| 'medium' \| 'large'`|`'medium'`||
2020-10-22 14:30:14 +08:00
|on-update:filters|`(filters: { [string \| number]: Array<string \| number> \| string \| number }, initiatorColumn: Column)`||
|on-update:sorter|`(options: { columnKey: string \| number, sorter: 'default' \| function \| boolean, order: 'ascend' \| 'descend' \| false } \| null) => any`|`undefined`|If there won't be a active sorter after change, `options` will be `null`|
|on-update:page|`(page: number)`|`undefined`||
|on-update:page-size|`(pageSize: number) => any`|`undefined`||
|on-update:checked-row-keys|`(keys: Array<string \| number>) => any`|`undefined`||
2019-12-26 23:59:41 +08:00
2020-01-31 17:02:33 +08:00
## Methods
These methods can help you control table in an uncontrolled manner. However, it's not recommended to use them to implement some async operations. If async operations is needed, use table in a **controlled** manner.
2019-12-26 23:59:41 +08:00
2020-01-31 17:02:33 +08:00
|Name|Type|Description|
|-|-|-|
|filters|`(filters: { [string \| number]: Array<string \| number> \| string \| number }) => void`|Set the active filters of the table.|
|sort|`(columnKey: string \| null, order: 'ascend' \| 'descend' \| false) => void`|If columnKey set to `null`, it is the same as clearSorter.|
2020-02-05 12:21:18 +08:00
|page|`(page: number) => void`||
|clearFilters|`() => void`||
|clearSorter|`() => void`||
2019-12-26 23:59:41 +08:00
2020-01-31 17:02:33 +08:00
## Events
|Name|Parameters|Description|
|-|-|-|
|filters-change|`(filters: { [string \| number]: Array<string \| number> }, initiatorColumn: Column)`||
2020-05-31 14:30:05 +08:00
|sorter-change|`(data: { columnKey: string \| number, sorter: 'default' \| function \| boolean, order: 'ascend' \| 'descend' \| false } \| null)`|If there won't be a active sorter after change, sorter-change will emit `null`|
2020-01-31 17:02:33 +08:00
|page-change|`(page: number)`||
|page-size-change|`(pageSize: number)`||
|checked-row-keys-change|`(keys: Array<string \| number>)`||
2019-12-26 23:59:41 +08:00
2020-01-31 17:02:33 +08:00
## API
### Column Properties
|Name|Type|Default|Description|
2020-01-31 17:02:33 +08:00
|-|-|-|-|
2020-10-07 03:59:33 +08:00
|render|`(rowData: Object) => VNode \| Array<VNode>`|`null`|Render function of column row cell|
2020-01-31 17:02:33 +08:00
|type|`'default' \| 'selection'`|`default`||
2020-05-31 14:33:44 +08:00
|disabled|`(rowData: Object, index: number) => boolean`|`() => false`||
2020-01-31 17:02:33 +08:00
|align|`'left' \| 'right' \| 'center'`|`'left'`|Text align in column|
|ellipsis|`boolean`|`false`||
|className|`string`|`null`||
2020-02-29 14:55:52 +08:00
|title|`string \| (() => VNode \| Array<VNode>)`|`null`|Can be a render function|
2020-02-04 22:43:40 +08:00
|key|`string`||Unique key of this column, **required** when table's row-key is not set.|
2020-01-31 17:02:33 +08:00
|sorter|`boolean \| function \| 'default'`|`false`|The sorter of the column. If set `'default'`, it will use a basic builtin compare function. If set to `true`, it will only display sort icon on the column, which can be used in async status. Otherwise it works like `Array.sort`'s compare function.|
|defaultSortOrder|`'descend' \| 'ascend' \| false`|`false`|The default sort order of the table in uncontrolled manner|
|sortOrder|`'descend' \| 'ascend' \| false \| null`|`null`|The controlled sort order of the column. If it is not `null`, the table's sort status will be in controlled mode. If multiple columns' sortOrder is set, the first one will affect.|
2020-05-31 14:33:44 +08:00
|filter|`boolean \| (optionValue: string \| number, rowData: Object) => boolean \| 'default'`|`false`|The filter of the column. If set to `true`, it will only display filter button on the column, which can be used in async status.|
2020-01-31 17:02:33 +08:00
|filterMode|`'and' \| 'or'`|`'or'`||
|filterOptions|`Array<{ label: string, value: string \| number}>`|`[]`||
|filterOptionValues|`Array<string \| number> \| null`|`undefined`|The active filter option values in controlled manner. If not set, the filter of the column works in an uncontrolled manner. (works when there are multiple filters)|
|filterOptionValue|`string \| number \| null`|`undefined`|The active filter option value in controlled manner. If not set, the filter of the column works in an uncontrolled manner. (works when not using multiple filters)|
|defaultFilterOptionValues|`Array<string \| number>`|`[]`|The default active filter option values in uncontrolled manner. (works when there are multiple filters)|
|defaultFilterOptionValue|`string \| number`|`null`|The default active filter option value in uncontrolled manner. (works when not using multiple filters)|
2020-01-31 17:02:33 +08:00
|filterMultiple|`boolean`|`true`||
|fixed|`'left \| 'right' \| false`|`false`||
2020-02-17 09:55:20 +08:00
|width|`number \| string`|`null`|Width of the column, **required** when fixed|