@hinen/pro-element-plus 1.7.17 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/DataTable/DataTable.vue.d.ts +24 -6
- package/dist/components/DataTable/DataTable.vue.d.ts.map +1 -1
- package/dist/components/DataTable/props.d.ts +11 -2
- package/dist/components/DataTable/props.d.ts.map +1 -1
- package/dist/components/DataTable/types.d.ts +14 -1
- package/dist/components/DataTable/types.d.ts.map +1 -1
- package/dist/components/DataTable/useDataTable.d.ts.map +1 -1
- package/dist/components/FormFields/FormCascadeSelect/FormCascadeSelect.test.d.ts +2 -0
- package/dist/components/FormFields/FormCascadeSelect/FormCascadeSelect.test.d.ts.map +1 -0
- package/dist/components/FormFields/FormCascadeSelect/FormCascadeSelect.vue.d.ts +136 -146
- package/dist/components/FormFields/FormCascadeSelect/FormCascadeSelect.vue.d.ts.map +1 -1
- package/dist/components/FormFields/FormCascadeSelect/props.d.ts +112 -114
- package/dist/components/FormFields/FormCascadeSelect/props.d.ts.map +1 -1
- package/dist/components/FormFields/FormCascadeSelect/types.d.ts +24 -1
- package/dist/components/FormFields/FormCascadeSelect/types.d.ts.map +1 -1
- package/dist/components/FormFields/FormTagInput/FormTagInput.vue.d.ts.map +1 -1
- package/dist/components/FormFields/FormTreeSelect/props.d.ts +3 -1
- package/dist/components/FormFields/FormTreeSelect/props.d.ts.map +1 -1
- package/dist/index.cjs +14 -14
- package/dist/index.js +2613 -2203
- package/dist/skills/building-form-workflows/SKILL.md +77 -0
- package/dist/skills/building-form-workflows/references/examples.md +47 -0
- package/dist/skills/building-form-workflows/references/field-selection.md +16 -0
- package/dist/skills/building-form-workflows/references/gotchas.md +10 -0
- package/dist/skills/building-form-workflows/references/workflow.md +21 -0
- package/dist/skills/building-modal-workflows/SKILL.md +79 -0
- package/dist/skills/building-modal-workflows/references/examples.md +104 -0
- package/dist/skills/building-modal-workflows/references/gotchas.md +19 -0
- package/dist/skills/building-modal-workflows/references/workflow.md +17 -0
- package/dist/skills/building-query-pages/SKILL.md +81 -0
- package/dist/skills/building-query-pages/references/examples.md +64 -0
- package/dist/skills/building-query-pages/references/field-selection.md +24 -0
- package/dist/skills/building-query-pages/references/gotchas.md +10 -0
- package/dist/skills/building-query-pages/references/workflow.md +22 -0
- package/dist/skills/building-selection-inputs/SKILL.md +85 -0
- package/dist/skills/building-selection-inputs/references/examples.md +87 -0
- package/dist/skills/building-selection-inputs/references/gotchas.md +19 -0
- package/dist/skills/building-selection-inputs/references/selection-guide.md +47 -0
- package/dist/skills/choosing-components/SKILL.md +78 -0
- package/dist/skills/choosing-components/references/component-groups.md +37 -0
- package/dist/skills/choosing-components/references/examples.md +91 -0
- package/dist/skills/choosing-components/references/gotchas.md +10 -0
- package/dist/skills/choosing-components/references/selection-guide.md +40 -0
- package/dist/skills/optimizing-component-skills/REVIEW.md +775 -0
- package/dist/skills/using-checkbox-group/SKILL.md +91 -0
- package/dist/skills/using-checkbox-group/references/examples.md +55 -0
- package/dist/skills/using-checkbox-group/references/gotchas.md +13 -0
- package/dist/skills/using-checkbox-group/references/props.md +83 -0
- package/dist/skills/using-config-provider/SKILL.md +96 -0
- package/dist/skills/using-config-provider/references/examples.md +38 -0
- package/dist/skills/using-config-provider/references/gotchas.md +13 -0
- package/dist/skills/using-config-provider/references/props.md +38 -0
- package/dist/skills/using-data-select/SKILL.md +127 -0
- package/dist/skills/using-data-select/references/examples.md +67 -0
- package/dist/skills/using-data-select/references/gotchas.md +19 -0
- package/dist/skills/using-data-select/references/props.md +126 -0
- package/dist/skills/using-data-table/SKILL.md +289 -0
- package/dist/skills/using-data-table/references/examples.md +347 -0
- package/dist/skills/using-data-table/references/gotchas.md +114 -0
- package/dist/skills/using-data-table/references/props.md +375 -0
- package/dist/skills/using-drawer/SKILL.md +104 -0
- package/dist/skills/using-drawer/references/examples.md +109 -0
- package/dist/skills/using-drawer/references/gotchas.md +16 -0
- package/dist/skills/using-drawer/references/props.md +105 -0
- package/dist/skills/using-ellipsis-text/SKILL.md +105 -0
- package/dist/skills/using-ellipsis-text/references/examples.md +71 -0
- package/dist/skills/using-ellipsis-text/references/gotchas.md +19 -0
- package/dist/skills/using-ellipsis-text/references/props.md +97 -0
- package/dist/skills/using-form-autocomplete/SKILL.md +87 -0
- package/dist/skills/using-form-autocomplete/references/examples.md +62 -0
- package/dist/skills/using-form-autocomplete/references/gotchas.md +13 -0
- package/dist/skills/using-form-autocomplete/references/props.md +100 -0
- package/dist/skills/using-form-cascade-select/SKILL.md +82 -0
- package/dist/skills/using-form-cascade-select/references/examples.md +59 -0
- package/dist/skills/using-form-cascade-select/references/gotchas.md +13 -0
- package/dist/skills/using-form-cascade-select/references/props.md +138 -0
- package/dist/skills/using-form-checkbox-group/SKILL.md +83 -0
- package/dist/skills/using-form-checkbox-group/references/examples.md +61 -0
- package/dist/skills/using-form-checkbox-group/references/gotchas.md +13 -0
- package/dist/skills/using-form-checkbox-group/references/props.md +85 -0
- package/dist/skills/using-form-date-picker/SKILL.md +79 -0
- package/dist/skills/using-form-date-picker/references/examples.md +54 -0
- package/dist/skills/using-form-date-picker/references/gotchas.md +10 -0
- package/dist/skills/using-form-date-picker/references/props.md +99 -0
- package/dist/skills/using-form-fields/SKILL.md +101 -0
- package/dist/skills/using-form-fields/references/examples.md +45 -0
- package/dist/skills/using-form-fields/references/gotchas.md +6 -0
- package/dist/skills/using-form-fields/references/props.md +57 -0
- package/dist/skills/using-form-item/SKILL.md +92 -0
- package/dist/skills/using-form-item/references/examples.md +59 -0
- package/dist/skills/using-form-item/references/gotchas.md +13 -0
- package/dist/skills/using-form-item/references/props.md +85 -0
- package/dist/skills/using-form-number/SKILL.md +82 -0
- package/dist/skills/using-form-number/references/examples.md +66 -0
- package/dist/skills/using-form-number/references/gotchas.md +13 -0
- package/dist/skills/using-form-number/references/props.md +82 -0
- package/dist/skills/using-form-radio-group/SKILL.md +83 -0
- package/dist/skills/using-form-radio-group/references/examples.md +53 -0
- package/dist/skills/using-form-radio-group/references/gotchas.md +13 -0
- package/dist/skills/using-form-radio-group/references/props.md +81 -0
- package/dist/skills/using-form-rate/SKILL.md +86 -0
- package/dist/skills/using-form-rate/references/examples.md +60 -0
- package/dist/skills/using-form-rate/references/gotchas.md +16 -0
- package/dist/skills/using-form-rate/references/props.md +88 -0
- package/dist/skills/using-form-select/SKILL.md +94 -0
- package/dist/skills/using-form-select/references/examples.md +67 -0
- package/dist/skills/using-form-select/references/gotchas.md +13 -0
- package/dist/skills/using-form-select/references/props.md +87 -0
- package/dist/skills/using-form-switch/SKILL.md +81 -0
- package/dist/skills/using-form-switch/references/examples.md +54 -0
- package/dist/skills/using-form-switch/references/gotchas.md +10 -0
- package/dist/skills/using-form-switch/references/props.md +83 -0
- package/dist/skills/using-form-tag-input/SKILL.md +83 -0
- package/dist/skills/using-form-tag-input/references/examples.md +53 -0
- package/dist/skills/using-form-tag-input/references/gotchas.md +13 -0
- package/dist/skills/using-form-tag-input/references/props.md +80 -0
- package/dist/skills/using-form-text/SKILL.md +82 -0
- package/dist/skills/using-form-text/references/examples.md +66 -0
- package/dist/skills/using-form-text/references/gotchas.md +13 -0
- package/dist/skills/using-form-text/references/props.md +98 -0
- package/dist/skills/using-form-time-picker/SKILL.md +78 -0
- package/dist/skills/using-form-time-picker/references/examples.md +53 -0
- package/dist/skills/using-form-time-picker/references/gotchas.md +10 -0
- package/dist/skills/using-form-time-picker/references/props.md +89 -0
- package/dist/skills/using-form-tree-select/SKILL.md +82 -0
- package/dist/skills/using-form-tree-select/references/examples.md +55 -0
- package/dist/skills/using-form-tree-select/references/gotchas.md +13 -0
- package/dist/skills/using-form-tree-select/references/props.md +86 -0
- package/dist/skills/using-image/SKILL.md +88 -0
- package/dist/skills/using-image/references/examples.md +31 -0
- package/dist/skills/using-image/references/gotchas.md +13 -0
- package/dist/skills/using-image/references/props.md +91 -0
- package/dist/skills/using-modal/SKILL.md +113 -0
- package/dist/skills/using-modal/references/examples.md +122 -0
- package/dist/skills/using-modal/references/gotchas.md +16 -0
- package/dist/skills/using-modal/references/props.md +100 -0
- package/dist/skills/using-query-form/SKILL.md +134 -0
- package/dist/skills/using-query-form/references/examples.md +103 -0
- package/dist/skills/using-query-form/references/gotchas.md +19 -0
- package/dist/skills/using-query-form/references/props.md +146 -0
- package/dist/skills/using-radio-group/SKILL.md +91 -0
- package/dist/skills/using-radio-group/references/examples.md +55 -0
- package/dist/skills/using-radio-group/references/gotchas.md +13 -0
- package/dist/skills/using-radio-group/references/props.md +83 -0
- package/dist/skills/using-select/SKILL.md +93 -0
- package/dist/skills/using-select/references/examples.md +50 -0
- package/dist/skills/using-select/references/gotchas.md +13 -0
- package/dist/skills/using-select/references/props.md +90 -0
- package/dist/style.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# DataSelect props
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
`DataSelect` extends the select surface with option-source modes, request handling, custom filtering, and request debounce behavior.
|
|
6
|
+
|
|
7
|
+
Choose the option source first. Most later decisions depend on that.
|
|
8
|
+
|
|
9
|
+
## Source modes
|
|
10
|
+
|
|
11
|
+
### 1. `options`
|
|
12
|
+
|
|
13
|
+
Use for local option arrays.
|
|
14
|
+
|
|
15
|
+
### 2. `valueEnum`
|
|
16
|
+
|
|
17
|
+
Use for lightweight value-to-label maps.
|
|
18
|
+
|
|
19
|
+
### 3. `request`
|
|
20
|
+
|
|
21
|
+
Use when options should be loaded asynchronously.
|
|
22
|
+
|
|
23
|
+
The request signature is:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
(filterContent?: string, params?: Record<string, any>) =>
|
|
27
|
+
Promise<DataSelectOptionType[]>;
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Core props
|
|
31
|
+
|
|
32
|
+
### `options`
|
|
33
|
+
|
|
34
|
+
Local option source.
|
|
35
|
+
|
|
36
|
+
Supports flat options and grouped options through nested `options` arrays.
|
|
37
|
+
|
|
38
|
+
### `valueEnum`
|
|
39
|
+
|
|
40
|
+
Compact mapping from value to label.
|
|
41
|
+
|
|
42
|
+
Use this when writing an explicit options array would add little value.
|
|
43
|
+
|
|
44
|
+
### `request`
|
|
45
|
+
|
|
46
|
+
Async option loader used when `options` and `valueEnum` are absent.
|
|
47
|
+
|
|
48
|
+
The component watches both filter content and `params`, then refreshes the remote options.
|
|
49
|
+
|
|
50
|
+
### `params`
|
|
51
|
+
|
|
52
|
+
Extra request parameters passed into `request`.
|
|
53
|
+
|
|
54
|
+
Use this when the option set depends on parent state such as project, tenant, or tab context.
|
|
55
|
+
|
|
56
|
+
### `filterable`
|
|
57
|
+
|
|
58
|
+
Accepts:
|
|
59
|
+
|
|
60
|
+
- `true` for local filtering
|
|
61
|
+
- `'remote'` for remote filtering semantics
|
|
62
|
+
|
|
63
|
+
`'remote'` skips local option filtering and treats search text as a remote-query concern.
|
|
64
|
+
|
|
65
|
+
### `filterOption`
|
|
66
|
+
|
|
67
|
+
Custom local filtering function.
|
|
68
|
+
|
|
69
|
+
Used only when the component is not in remote filtering mode.
|
|
70
|
+
|
|
71
|
+
### `disableOption`
|
|
72
|
+
|
|
73
|
+
Dynamic disable logic.
|
|
74
|
+
|
|
75
|
+
Signature:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
(filterContent: string, option: DataSelectOptionType) => boolean;
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### `debounceTime` and `debounceWaitTime`
|
|
82
|
+
|
|
83
|
+
Request debounce controls.
|
|
84
|
+
|
|
85
|
+
Defaults:
|
|
86
|
+
|
|
87
|
+
- `debounceTime: 300`
|
|
88
|
+
- `debounceWaitTime: 500`
|
|
89
|
+
|
|
90
|
+
## Slots
|
|
91
|
+
|
|
92
|
+
Useful slots:
|
|
93
|
+
|
|
94
|
+
- `option`
|
|
95
|
+
- `header`
|
|
96
|
+
- `footer`
|
|
97
|
+
- `prefix`
|
|
98
|
+
- `empty`
|
|
99
|
+
- `loading`
|
|
100
|
+
- `tag`
|
|
101
|
+
- `label`
|
|
102
|
+
- default slot receiving `{ options }`
|
|
103
|
+
|
|
104
|
+
## Instance API
|
|
105
|
+
|
|
106
|
+
Exposed methods:
|
|
107
|
+
|
|
108
|
+
- `focus()`
|
|
109
|
+
- `blur()`
|
|
110
|
+
|
|
111
|
+
## Events
|
|
112
|
+
|
|
113
|
+
Useful events:
|
|
114
|
+
|
|
115
|
+
- `update:modelValue`
|
|
116
|
+
- `change`
|
|
117
|
+
- `search`
|
|
118
|
+
- `visible-change`
|
|
119
|
+
- `remove-tag`
|
|
120
|
+
- `popup-scroll`
|
|
121
|
+
|
|
122
|
+
## Import
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { DataSelect } from '@hinen/pro-element-plus';
|
|
126
|
+
```
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: using-data-table
|
|
3
|
+
description: Use when building a page-level list that combines filters, table rows, pagination, remote querying, or programmatic search and refresh control in one place.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Using DataTable
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Use `DataTable` for **page-level list views** where query controls, table rendering, pagination, loading and error UI, and optional programmatic control should live together.
|
|
11
|
+
|
|
12
|
+
`DataTable` is not just a table wrapper. It combines:
|
|
13
|
+
|
|
14
|
+
- query form generation from `columns`
|
|
15
|
+
- table rendering
|
|
16
|
+
- pagination
|
|
17
|
+
- remote querying through `queryFn`
|
|
18
|
+
- imperative control through `useDataTable()`
|
|
19
|
+
|
|
20
|
+
It supports two valid modes:
|
|
21
|
+
|
|
22
|
+
1. **Remote mode** — pass `queryFn`
|
|
23
|
+
2. **Static mode** — pass `data`
|
|
24
|
+
|
|
25
|
+
Choose it when one component should own the full **search → fetch → render → paginate → refresh** flow.
|
|
26
|
+
|
|
27
|
+
## Use it when
|
|
28
|
+
|
|
29
|
+
Use `DataTable` when a page needs several of these concerns together:
|
|
30
|
+
|
|
31
|
+
- filters and table rows belong to the same page-level component
|
|
32
|
+
- columns should define both display behavior and query behavior
|
|
33
|
+
- the page needs pagination, sorting, or refresh
|
|
34
|
+
- parent code needs to set search params or trigger table actions programmatically
|
|
35
|
+
- loading, empty, and error states should follow one standard shell
|
|
36
|
+
|
|
37
|
+
Strong signals this skill applies:
|
|
38
|
+
|
|
39
|
+
- admin list pages
|
|
40
|
+
- management consoles
|
|
41
|
+
- searchable resource lists
|
|
42
|
+
- tab pages with controlled list state
|
|
43
|
+
- pages that need toolbar actions tied to table state
|
|
44
|
+
|
|
45
|
+
## Prefer something else when
|
|
46
|
+
|
|
47
|
+
- you only need a standalone filter form
|
|
48
|
+
→ use `../using-query-form/SKILL.md`
|
|
49
|
+
- you are still shaping page structure and interaction model
|
|
50
|
+
→ use `../building-query-pages/SKILL.md`
|
|
51
|
+
- the same query-and-result surface should live inside an overlay shell instead of a normal page layout
|
|
52
|
+
→ use `../using-modal/SKILL.md` or `../using-drawer/SKILL.md` for the shell choice, then keep `DataTable` as the inner list shell
|
|
53
|
+
- you only need a very small static table with no search, no paging, and no imperative control
|
|
54
|
+
- the page layout is highly custom and should not be driven by column metadata
|
|
55
|
+
- multi-level nested headers are a primary requirement
|
|
56
|
+
- virtualization or infinite scrolling is more important than standard pagination
|
|
57
|
+
|
|
58
|
+
## Decision guide
|
|
59
|
+
|
|
60
|
+
Use `DataTable` if the answer is yes for **two or more** of these:
|
|
61
|
+
|
|
62
|
+
- Does the page need both filters and a table?
|
|
63
|
+
- Should `columns` also describe query inputs?
|
|
64
|
+
- Does the page need pagination or sorting?
|
|
65
|
+
- Will parent code need refresh, reset, or search-param control?
|
|
66
|
+
- Should loading, empty, and error handling follow a shared pattern?
|
|
67
|
+
|
|
68
|
+
If not, a simpler table or a standalone form is usually a better fit.
|
|
69
|
+
|
|
70
|
+
## Start with
|
|
71
|
+
|
|
72
|
+
1. Decide the mode first:
|
|
73
|
+
- **Remote mode** → `columns` + `queryFn`
|
|
74
|
+
- **Static mode** → `columns` + `data`
|
|
75
|
+
2. Keep `columns` as the source of truth for table and query metadata.
|
|
76
|
+
3. Add selection bar, `selection`, sticky layout, and custom slots only after the base flow is correct.
|
|
77
|
+
4. Use `useDataTable()` only when parent code truly needs imperative control.
|
|
78
|
+
|
|
79
|
+
5. Treat `highlightCurrentRow` intentionally.
|
|
80
|
+
In `DataTable`, this is not just native Element Plus row highlighting anymore. It enables the built-in single-select mode with a leading radio column.
|
|
81
|
+
|
|
82
|
+
## Minimal patterns
|
|
83
|
+
|
|
84
|
+
### Remote mode
|
|
85
|
+
|
|
86
|
+
Use this when the page should own querying, pagination, sorting, and refresh.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import {
|
|
90
|
+
DataTable,
|
|
91
|
+
defineDataTableColumns,
|
|
92
|
+
defineDataTableQueryFn,
|
|
93
|
+
} from '@hinen/pro-element-plus';
|
|
94
|
+
|
|
95
|
+
const columns = defineDataTableColumns<User>(() => [
|
|
96
|
+
{
|
|
97
|
+
label: 'Name',
|
|
98
|
+
prop: 'name',
|
|
99
|
+
formItemProps: {
|
|
100
|
+
placeholder: 'Search name',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
label: 'Status',
|
|
105
|
+
prop: 'status',
|
|
106
|
+
valueType: 'select',
|
|
107
|
+
valueEnum: {
|
|
108
|
+
active: { label: 'Active', type: 'success' },
|
|
109
|
+
disabled: { label: 'Disabled', type: 'info' },
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
const queryFn = defineDataTableQueryFn(
|
|
115
|
+
async ({ currentPage = 1, pageSize = 10, ...params }, sort) => {
|
|
116
|
+
const res = await fetchUsers({ currentPage, pageSize, ...params, sort });
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
data: res.list,
|
|
120
|
+
total: res.total,
|
|
121
|
+
success: res.success,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
```vue
|
|
128
|
+
<DataTable :columns="columns" :query-fn="queryFn" />
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Static mode
|
|
132
|
+
|
|
133
|
+
Use this when rows are already available and the page does not need built-in remote querying.
|
|
134
|
+
|
|
135
|
+
```vue
|
|
136
|
+
<DataTable :columns="columns" :data="rows" :pagination="false" />
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
In static mode:
|
|
140
|
+
|
|
141
|
+
- `queryFn` is not needed
|
|
142
|
+
- `refresh()` and `refetch()` are not available
|
|
143
|
+
- query-related helpers are usually unnecessary
|
|
144
|
+
|
|
145
|
+
## Programmatic control
|
|
146
|
+
|
|
147
|
+
Use `useDataTable()` when parent code needs imperative control.
|
|
148
|
+
|
|
149
|
+
Common methods:
|
|
150
|
+
|
|
151
|
+
- `setSearchParams()`
|
|
152
|
+
- `getSearchParams()`
|
|
153
|
+
- `resetPagination()`
|
|
154
|
+
- `resetAll()`
|
|
155
|
+
- `setCurrentPage()`
|
|
156
|
+
- `setPageSize()`
|
|
157
|
+
- `clearSelection()`
|
|
158
|
+
- `getDataSource()`
|
|
159
|
+
- `refresh()` / `refetch()` in remote mode only
|
|
160
|
+
|
|
161
|
+
Use this pattern when toolbars, tabs, route sync, or external controls need to coordinate the table.
|
|
162
|
+
|
|
163
|
+
For current-row control in single-select mode:
|
|
164
|
+
|
|
165
|
+
- use `setCurrentRow(row)` to select a row programmatically
|
|
166
|
+
- use `setCurrentRow()` to clear the current single-select row
|
|
167
|
+
- use `currentRowKey` together with `rowKey` for controlled current-row sync
|
|
168
|
+
- do not rely on row clicks to change the current row when `highlightCurrentRow` is enabled
|
|
169
|
+
- do not use `clearSelection()` to clear single-select current-row state; that method is for checkbox selection
|
|
170
|
+
|
|
171
|
+
## Controlled selection mode
|
|
172
|
+
|
|
173
|
+
`DataTable` supports two selection modes:
|
|
174
|
+
|
|
175
|
+
1. **Internal mode** — the component owns selection state (default)
|
|
176
|
+
2. **Controlled mode** — parent state owns selection via `v-model:selectedRowKeys`
|
|
177
|
+
|
|
178
|
+
### Internal mode
|
|
179
|
+
|
|
180
|
+
Use internal mode when the page does not need to read or manipulate selection from outside the component.
|
|
181
|
+
|
|
182
|
+
```vue
|
|
183
|
+
<DataTable :columns="columns" :query-fn="queryFn" row-selection />
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Controlled mode
|
|
187
|
+
|
|
188
|
+
Use controlled mode when parent code needs to:
|
|
189
|
+
|
|
190
|
+
- read selected row keys reactively
|
|
191
|
+
- set selection from external state
|
|
192
|
+
- sync selection with URL, storage, or other components
|
|
193
|
+
- clear or modify selection programmatically
|
|
194
|
+
|
|
195
|
+
```vue
|
|
196
|
+
<DataTable
|
|
197
|
+
v-model:selectedRowKeys="selectedKeys"
|
|
198
|
+
:columns="columns"
|
|
199
|
+
:query-fn="queryFn"
|
|
200
|
+
row-selection
|
|
201
|
+
/>
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
const selectedKeys = ref<DataTableSelectionKeyType[]>([]);
|
|
206
|
+
|
|
207
|
+
// Read selection
|
|
208
|
+
console.log(selectedKeys.value);
|
|
209
|
+
|
|
210
|
+
// Set selection
|
|
211
|
+
selectedKeys.value = ['id1', 'id2'];
|
|
212
|
+
|
|
213
|
+
// Clear selection
|
|
214
|
+
selectedKeys.value = [];
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Key differences
|
|
218
|
+
|
|
219
|
+
| Aspect | Internal mode | Controlled mode |
|
|
220
|
+
| ----------------- | ----------------------- | -------------------------------------------- |
|
|
221
|
+
| State owner | `DataTable` internal | Parent via `selectedKeys` |
|
|
222
|
+
| Prop | none | `v-model:selectedRowKeys` |
|
|
223
|
+
| Emit | `selectionChange` | `selectionChange` + `update:selectedRowKeys` |
|
|
224
|
+
| Initial selection | none | controlled by parent |
|
|
225
|
+
| Clear from parent | call `clearSelection()` | set model to `[]` |
|
|
226
|
+
|
|
227
|
+
### Important notes
|
|
228
|
+
|
|
229
|
+
- `selectedRowKeys` is typed as `DataTableSelectionKeyType[]` (string or number)
|
|
230
|
+
- When `v-model:selectedRowKeys` is provided, the component operates in controlled mode
|
|
231
|
+
- The `selection` prop remains for customization only, never for state control
|
|
232
|
+
- Cross-page selection requires `rowKey` in both modes
|
|
233
|
+
- Instance methods like `getSelectionRows()`, `toggleRowSelection()` still work in controlled mode
|
|
234
|
+
- `clearSelection()` still clears the internal selection, but in controlled mode you should update the parent state instead
|
|
235
|
+
|
|
236
|
+
## Slots
|
|
237
|
+
|
|
238
|
+
Use slots when the page needs light customization without replacing the standard shell:
|
|
239
|
+
|
|
240
|
+
- `toolbar`
|
|
241
|
+
- `selectionBar`
|
|
242
|
+
- `append`
|
|
243
|
+
- `empty`
|
|
244
|
+
- `error`
|
|
245
|
+
|
|
246
|
+
Prefer slots over rebuilding table scaffolding from scratch.
|
|
247
|
+
|
|
248
|
+
For checkbox selection review:
|
|
249
|
+
|
|
250
|
+
- `selection` is the public API for built-in checkbox review item customization
|
|
251
|
+
- `formatter(row)` customizes the built-in review tag text
|
|
252
|
+
- `render(...)` customizes each built-in review item
|
|
253
|
+
- `selectionBar.reviewPopoverProps` customizes the built-in 查看已选 popover (default placement is 'bottom-start')
|
|
254
|
+
- `rowKey` is required if the built-in checkbox review should stay correct across pages
|
|
255
|
+
- the `selectionBar` slot replaces the built-in review UI instead of extending it
|
|
256
|
+
- in cross-page checkbox mode, the `selectionBar` slot receives the aggregated selected rows, so Search/Reset or pagination should not make that slot-level selection disappear
|
|
257
|
+
- `selectionChange` and `getSelectionRows()` still describe the current page only
|
|
258
|
+
- single-select behavior from `highlightCurrentRow` is unchanged
|
|
259
|
+
|
|
260
|
+
## Common mistakes
|
|
261
|
+
|
|
262
|
+
- Treating `DataTable` as a dumb table instead of a page-level query shell
|
|
263
|
+
- Returning the wrong shape from `queryFn`
|
|
264
|
+
- Passing `data` and still calling `refresh()` or `refetch()`
|
|
265
|
+
- Forgetting that query form generation depends on `columns`
|
|
266
|
+
- Using `DataTable` for highly custom layouts that are not column-driven
|
|
267
|
+
- Ignoring `enabled` when queries depend on prerequisites
|
|
268
|
+
- Accidentally hiding pagination through `hidePaginationWhenEmpty`
|
|
269
|
+
- Assuming `success` is optional in remote mode
|
|
270
|
+
- Expecting cross-page checkbox review state without `rowKey`
|
|
271
|
+
- Treating `selectionChange` or `getSelectionRows()` as cross-page aggregate APIs
|
|
272
|
+
- Assuming the `selectionBar` slot keeps the built-in review UI
|
|
273
|
+
- Treating `selectionBar.reviewPopoverProps` as item-render customization instead of popover-container customization
|
|
274
|
+
- Treating `highlightCurrentRow` as a visual-only prop in `DataTable`
|
|
275
|
+
- Expecting row clicks to change the current row when built-in single-select mode is active
|
|
276
|
+
- Using `currentRowKey` without `rowKey` and expecting controlled current-row sync to work
|
|
277
|
+
|
|
278
|
+
## Related skills
|
|
279
|
+
|
|
280
|
+
- Standalone filter form: `../using-query-form/SKILL.md`
|
|
281
|
+
- Page structure and list-page shaping: `../building-query-pages/SKILL.md`
|
|
282
|
+
- Shared empty and error rendering: `../using-config-provider/SKILL.md`
|
|
283
|
+
- Overlay shells that may host this list surface: `../using-modal/SKILL.md`, `../using-drawer/SKILL.md`
|
|
284
|
+
|
|
285
|
+
## References
|
|
286
|
+
|
|
287
|
+
- Props: `./references/props.md`
|
|
288
|
+
- Examples: `./references/examples.md`
|
|
289
|
+
- Gotchas: `./references/gotchas.md`
|