Skip to content

Commit fe41154

Browse files
authored
row-selection initial docs (TanStack#3871)
1 parent 015dd70 commit fe41154

2 files changed

Lines changed: 346 additions & 2 deletions

File tree

docs/api/column-pinning.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Sets or updates the `state.columnPinning` state.
8787
resetColumnPinning: () => void
8888
```
8989
90-
Resets the **columnPinning** state for the table.
90+
Resets the **columnPinning** state for the table back to its initial state.
9191
9292
### `pinColumn`
9393

docs/api/row-selection.md

Lines changed: 345 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,347 @@
1+
---
2+
name: Row Selection
3+
route: /api/row-selection
4+
menu: API
5+
---
6+
7+
## Examples
8+
9+
Want to skip to the implementation? Check out these examples:
10+
11+
- [row-selection](../examples/row-selection)
12+
13+
## State
14+
15+
Row selection state is stored on the table instance using the following shape:
16+
17+
```tsx
18+
export type RowSelectionState = Record<string, boolean>
19+
20+
export type RowSelectionTableState = {
21+
rowSelection: RowSelectionState
22+
}
23+
```
24+
25+
## Table Options
26+
27+
### `autoResetRowSelection`
28+
29+
```tsx
30+
autoResetRowSelection?: boolean
31+
```
32+
33+
If set will enable/disable the automatic reset of row selection when it's dependent rows/states change.
34+
35+
### `enableRowSelection`
36+
37+
```tsx
38+
enableRowSelection?: boolean | ((row: Row<TGenerics>) => boolean)
39+
```
40+
41+
Enables/disables row selection for all rows in the table, or a funtion that enables/disables row selection for each row.
42+
43+
### `enableMultiRowSelection`
44+
45+
```tsx
46+
enableMultiRowSelection?: boolean | ((row: Row<TGenerics>) => boolean)
47+
```
48+
49+
Enables/disables multiple row selection for all rows in the table, or a funtion that enables/disables multiple row selection for each row.
50+
51+
TODO clarify
52+
53+
### `enableSubRowSelection`
54+
55+
```tsx
56+
enableSubRowSelection?: boolean | ((row: Row<TGenerics>) => boolean)
57+
```
58+
59+
Enables/disables automatic sub-row selection when a parent row is selected, or a funtion that enables/disables automatic sub-row selection for each row.
60+
61+
(Use in combination with expanding or grouping features)
62+
63+
### `onRowSelectionChange`
64+
65+
```tsx
66+
onRowSelectionChange?: OnChangeFn<RowSelectionState>
67+
```
68+
69+
If provided, this function will be called with an `updaterFn` when `state.rowSelection` changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.
70+
71+
## Table Instance API
72+
73+
### `queueResetRowSelection`
74+
75+
```tsx
76+
queueResetRowSelection: () => void
77+
```
78+
179
TODO
280
3-
Please duplicate a completed api file as a template to get started!
81+
### `getToggleRowSelectedProps`
82+
83+
```tsx
84+
type ToggleRowSelectedProps = {
85+
onChange?: (e: unknown) => void
86+
checked?: boolean
87+
title?: string
88+
indeterminate?: boolean
89+
}
90+
91+
getToggleRowSelectedProps: <TGetter extends Getter<ToggleRowSelectedProps>>(
92+
rowId: string,
93+
userProps?: TGetter
94+
) => undefined | PropGetterValue<ToggleRowSelectedProps, TGetter>
95+
```
96+
97+
Returns the props for the `<input type="checkbox" />` element in a row that will toggle row selection and provides checked/indeterminate state.
98+
99+
### `getToggleAllRowsSelectedProps`
100+
101+
```tsx
102+
type ToggleRowSelectedProps = {
103+
onChange?: (e: unknown) => void
104+
checked?: boolean
105+
title?: string
106+
indeterminate?: boolean
107+
}
108+
109+
getToggleAllRowsSelectedProps: <
110+
TGetter extends Getter<ToggleRowSelectedProps>
111+
>(
112+
userProps?: TGetter
113+
) => undefined | PropGetterValue<ToggleRowSelectedProps, TGetter>
114+
```
115+
116+
Returns the props for the `<input type="checkbox" />` element in a column header that will toggle row selection for all rows in the table and provides checked/indeterminate state.
117+
118+
### `getToggleAllPageRowsSelectedProps`
119+
120+
```tsx
121+
getToggleAllPageRowsSelectedProps: <
122+
TGetter extends Getter<ToggleRowSelectedProps>
123+
>(
124+
userProps?: TGetter
125+
) => undefined | PropGetterValue<ToggleRowSelectedProps, TGetter>
126+
```
127+
128+
Returns the props for the `<input type="checkbox" />` element in a column header that will toggle row selection for all rows on the current page and provides checked/indeterminate state.
129+
130+
### `setRowSelection`
131+
132+
```tsx
133+
setRowSelection: (updater: Updater<RowSelectionState>) => void
134+
```
135+
136+
Sets or updates the `state.rowSelection` state.
137+
138+
### `resetRowSelection`
139+
140+
```tsx
141+
resetRowSelection: () => void
142+
```
143+
144+
Resets the **rowSelection** state for the table back to its initial state.
145+
146+
### `toggleRowSelected`
147+
148+
```tsx
149+
toggleRowSelected: (rowId: string, value?: boolean) => void
150+
```
151+
152+
Selects/deselects a row.
153+
154+
### `getRowCanSelect`
155+
156+
```tsx
157+
getRowCanSelect: (rowId: string) => boolean
158+
```
159+
160+
Returns whether or not a row can be selected.
161+
162+
### `getRowCanSelectSubRows`
163+
164+
```tsx
165+
getRowCanSelectSubRows: (rowId: string) => boolean
166+
```
167+
168+
Returns whether or not a row's sub-rows can be automatically selected when the parent row is selected.
169+
170+
### `getRowCanMultiSelect`
171+
172+
```tsx
173+
getRowCanMultiSelect: (rowId: string) => boolean
174+
```
175+
176+
Returns whether or not a row can be multi-selected. TODO clarify
177+
178+
### `getRowIsSelected`
179+
180+
```tsx
181+
getRowIsSelected: (rowId: string) => boolean
182+
```
183+
184+
Returns whether or not a row is selected.
185+
186+
### `getRowIsSomeSelected`
187+
188+
```tsx
189+
getRowIsSomeSelected: (rowId: string) => boolean
190+
```
191+
192+
Returns whether or not any sub-rows of a row are selected.
193+
194+
### `getIsAllRowsSelected`
195+
196+
```tsx
197+
getIsAllRowsSelected: () => boolean
198+
```
199+
200+
Returns whether or not all rows in the table are selected.
201+
202+
### `getIsAllPageRowsSelected`
203+
204+
```tsx
205+
getIsAllPageRowsSelected: () => boolean
206+
```
207+
208+
Returns whether or not all rows on the current page are selected.
209+
210+
### `getIsSomeRowsSelected`
211+
212+
```tsx
213+
getIsSomeRowsSelected: () => boolean
214+
```
215+
216+
Returns whether or not any rows in the table are selected.
217+
218+
### `getIsSomePageRowsSelected`
219+
220+
```tsx
221+
getIsSomePageRowsSelected: () => boolean
222+
```
223+
224+
Returns whether or not any rows on the current page are selected.
225+
226+
### `queueResetRowSelection`
227+
228+
```tsx
229+
queueResetRowSelection: () => void
230+
```
231+
232+
TODO
233+
234+
### `toggleAllRowsSelected`
235+
236+
```tsx
237+
toggleAllRowsSelected: (value: boolean) => void
238+
```
239+
240+
Selects/deselects all rows in the table.
241+
242+
### `toggleAllPageRowsSelected`
243+
244+
```tsx
245+
toggleAllPageRowsSelected: (value: boolean) => void
246+
```
247+
248+
Selects/deselects all rows on the current page.
249+
250+
### `getPreSelectedRowModel`
251+
252+
```tsx
253+
getPreSelectedRowModel: () => RowModel<TGenerics>
254+
```
255+
256+
TODO
257+
258+
### `queueResetRowSelection`
259+
260+
```tsx
261+
queueResetRowSelection: () => void
262+
```
263+
264+
TODO
265+
266+
### `getSelectedRowModel`
267+
268+
```tsx
269+
getSelectedRowModel: () => RowModel<TGenerics>
270+
```
271+
272+
TODO
273+
274+
### `getFilteredSelectedRowModel`
275+
276+
```tsx
277+
getFilteredSelectedRowModel: () => RowModel<TGenerics>
278+
```
279+
280+
TODO
281+
282+
### `getGroupedSelectedRowModel`
283+
284+
```tsx
285+
getGroupedSelectedRowModel: () => RowModel<TGenerics>
286+
```
287+
288+
TODO
289+
290+
## Row API
291+
292+
### `getIsSelected`
293+
294+
```tsx
295+
getIsSelected: () => boolean
296+
```
297+
298+
Returns whether or not the row is selected.
299+
300+
### `getIsSomeSelected`
301+
302+
```tsx
303+
getIsSomeSelected: () => boolean
304+
```
305+
306+
Returns whether or not some of the row's sub rows are selected.
307+
308+
### `getCanSelect`
309+
310+
```tsx
311+
getCanSelect: () => boolean
312+
```
313+
314+
Returns whether or not the row can be selected.
315+
316+
### `getCanMultiSelect`
317+
318+
```tsx
319+
getCanMultiSelect: () => boolean
320+
```
321+
322+
Returns whether or not the row can multi-select. TODO clarify
323+
324+
### `toggleSelected`
325+
326+
```tsx
327+
toggleSelected: (value?: boolean) => void
328+
```
329+
330+
Selects/deselects the row.
331+
332+
### `getToggleSelectedProps`
333+
334+
```tsx
335+
type ToggleRowSelectedProps = {
336+
onChange?: (e: unknown) => void
337+
checked?: boolean
338+
title?: string
339+
indeterminate?: boolean
340+
}
341+
342+
getToggleSelectedProps: <TGetter extends Getter<ToggleRowSelectedProps>>(
343+
userProps?: TGetter
344+
) => undefined | PropGetterValue<ToggleRowSelectedProps, TGetter>
345+
```
346+
347+
Returns the props for the `<input type="checkbox" />` element in the row that will toggle row selection and provides checked/indeterminate state.

0 commit comments

Comments
 (0)