You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/List.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -486,7 +486,7 @@ const Dashboard = () => (
486
486
)
487
487
```
488
488
489
-
Please note that the selection state is not synced in the URL but in a global store using the resource as key. Thus, all lists in the page using the same resource will share the same synced selection state. This is a design choice because if row selection is not tied to a resource, then when a user deletes a record it may remain selected without any ability to unselect it. If you want to allow custom `storeKey`'s for managing selection state, you will have to implement your own `useListController` hook and pass a custom key to the `useRecordSelection` hook. You will then need to implement your own `DeleteButton` and `BulkDeleteButton` to manually unselect rows when deleting records. You can still opt out of all store interactions including selection if you set it to `false`.
489
+
Please note that the selection state is not synced in the URL but in a global store using the resource and, if provided, `storeKey`as part of the key. Thus, all lists in the page using the same resource and `storeKey`will share the same synced selection state. This is a design choice because if row selection is not tied to a resource, then when a user deletes a record it may remain selected without any ability to unselect it. You can still opt out of all store interactions for list state if you set it to `false`.
490
490
491
491
## `empty`
492
492
@@ -1097,7 +1097,9 @@ const Admin = () => {
1097
1097
1098
1098
**Tip:** The `storeKey` is actually passed to the underlying `useListController` hook, which you can use directly for more complex scenarios. See the [`useListController` doc](./useListController.md#storekey) for more info.
1099
1099
1100
-
**Note:***Selection state* will remain linked to a resource-based key regardless of the specified `storeKey` string. This is a design choice because if row selection is not tied to a resource, then when a user deletes a record it may remain selected without any ability to unselect it. If you want to allow custom `storeKey`'s for managing selection state, you will have to implement your own `useListController` hook and pass a custom key to the `useRecordSelection` hook. You will then need to implement your own `DeleteButton` and `BulkDeleteButton` to manually unselect rows when deleting records. You can still opt out of all store interactions including selection if you set it to `false`.
1100
+
**Tip:** The `storeKey` is also passed to the underlying `useRecordSelection` hook, so that lists with different storeKeys for same resource will have independent selection states.
1101
+
1102
+
**Tip:** Setting `storeKey` to `false` will opt out of all store interactions including selection.
Copy file name to clipboardExpand all lines: docs/useUnselect.md
+109-1Lines changed: 109 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,9 @@ title: "useUnselect"
5
5
6
6
# `useUnselect`
7
7
8
-
This hook returns a function that unselects lines in the current `<DataTable>` that match an array of ids. Pass the name of the resource to the hook as argument.
8
+
This hook returns a function that unselects lines in a `<DataTable>` that match an array of ids.
`useUnselect` accepts two parameters. Both are optional:
34
+
35
+
-[`resource`](#resource): The resource name. If not specified, the hook will only update the locally stored selection state (changes are not persisted in the Store).
36
+
-[`storeKey`](#storekey): The store key to use. If not specified, the hook will derive the store key from the `resource`. It should match with the `storeKey` used in the parent `<List>`.
If not specified, the hook will only update the locally stored selection state (changes are not persisted in the Store). This is notably useful when the parent `<List>` has the [`storeKey`](./List.md#storekey) prop set to `false`.
`useUnselect` returns a function taking up to two parameters:
113
+
114
+
-`ids`: An array of record ids to unselect.
115
+
-`fromAllStoreKeys`: A boolean indicating whether to unselect the records across all storeKeys used with this resource. Defaults to `false`. Set this to `true` for instance when the records are deleted, to ensure they don't remain selected in other lists.
`useUnselectAll` accepts two parameters. Both are optional:
30
+
31
+
-[`resource`](#resource): The resource name. If not specified, the hook will only update the locally stored selection state (changes are not persisted in the Store).
32
+
-[`storeKey`](#storekey): The store key to use. If not specified, the hook will derive the store key from the `resource`. It should match with the `storeKey` used in the parent `<List>`.
If not specified, the hook will only update the locally stored selection state (changes are not persisted in the Store). This is notably useful when the parent `<List>` has the [`storeKey`](./List.md#storekey) prop set to `false`.
`useUnselectAll` returns a function taking one optional parameter:
96
+
97
+
-`fromAllStoreKeys`: A boolean indicating whether to unselect the records across all storeKeys used with this resource. Defaults to `false`. Set this to `true` for instance when the records are deleted, to ensure they don't remain selected in other lists.
Copy file name to clipboardExpand all lines: docs_headless/src/content/docs/useUnselect.md
+109-1Lines changed: 109 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,9 @@
2
2
title: "useUnselect"
3
3
---
4
4
5
-
This hook returns a function that unselects lines in the current data table (see `<DataTableBase>`) that match an array of ids. Pass the name of the resource to the hook as argument.
5
+
This hook returns a function that unselects lines in a data table (see `<DataTableBase>`) that match an array of ids.
`useUnselect` accepts two parameters. Both are optional:
31
+
32
+
-[`resource`](#resource): The resource name. If not specified, the hook will only update the locally stored selection state (changes are not persisted in the Store).
33
+
-[`storeKey`](#storekey): The store key to use. If not specified, the hook will derive the store key from the `resource`. It should match the `storeKey` used by the parent controller (e.g. `useListController` or `<ListBase>`).
If not specified, the hook will only update the locally stored selection state (changes are not persisted in the Store). This is notably useful when the parent list has the [`storeKey`](./ListBase.md#storekey) prop set to `false`.
// Call useUnselect without arguments - local selection only
66
+
constunselect=useUnselect();
67
+
68
+
consthandleClick= () => {
69
+
unselect(selectedIds);
70
+
};
71
+
72
+
return (
73
+
<button onClick={handleClick}>
74
+
{`Unselect ${selectedIds.length} records`}
75
+
</button>
76
+
);
77
+
};
78
+
```
79
+
80
+
## `storeKey`
81
+
82
+
The default store key is derived from the resource name: `${resource}.selectedIds`.
83
+
84
+
You can customize the store key used by passing a `storeKey` parameter to the hook. Make sure it matches the `storeKey` used in the controller (`useListController` or `<ListBase>`).
85
+
86
+
The final store key used will be `${storeKey}.selectedIds`.
`useUnselect` returns a function taking up to two parameters:
110
+
111
+
-`ids`: An array of record ids to unselect.
112
+
-`fromAllStoreKeys`: A boolean indicating whether to unselect the records across all storeKeys used with this resource. Defaults to `false`. Set this to `true` for instance when the records are deleted, to ensure they don't remain selected in other lists.
0 commit comments