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
@@ -35,7 +35,6 @@ Here's how to add a custom action:
35
35
listThreeDotsMenu: true, // Show in three dots menu in list view
36
36
showButton: true, // Show as a button
37
37
showThreeDotsMenu: true, // Show in three-dots menu
38
-
bulkButton: true
39
38
}
40
39
}
41
40
]
@@ -51,11 +50,11 @@ Here's how to add a custom action:
51
50
-`action`: Handler function that executes when action is triggered for a **single** record
52
51
-`bulkHandler`: Handler function that executes when the action is triggered for **multiple** records at once (see [Bulk button with bulkHandler](#bulk-button-with-bulkhandler))
53
52
-`showIn`: Controls where the action appears
54
-
-`list`: whether to show in list view
55
-
-`listThreeDotsMenu`: whether to show in three dots menu in the list view
56
-
-`showButton`: whether to show as a button on show view
57
-
-`showThreeDotsMenu`: when to show in the three-dots menu of show view
58
-
-`bulkButton`: whether to show as a bulk-selection button in the list view
53
+
-`list`: whether to show as an icon button per row in the list view
54
+
-`listThreeDotsMenu`: whether to show in the three-dots menu per row in the list view
55
+
-`showButton`: whether to show as a button on the show view
56
+
-`showThreeDotsMenu`: whether to show in the three-dots menu of the show view
57
+
-`bulkButton`: whether to show as a bulk action button when rows are selected
59
58
60
59
### Bulk button with `action`
61
60
@@ -100,6 +99,15 @@ If your operation can be expressed more efficiently as a single batched query (e
100
99
101
100
> ☝️ When both `action` and `bulkHandler` are defined, AdminForth uses `bulkHandler` for bulk operations and `action` for single-record operations. When only `action` is defined and `bulkButton` is enabled, AdminForth falls back to `Promise.all` over individual `action` calls.
102
101
102
+
### Bulk-specific options
103
+
104
+
| Option | Type | Description |
105
+
|---|---|---|
106
+
|`showIn.bulkButton`|`boolean`| Show as a bulk action button in the list toolbar. |
107
+
|`bulkHandler`|`async ({ recordIds, adminUser, adminforth, resource, response, tr }) => { ok, error?, message? }`| Called with all selected IDs at once. Falls back to calling `action` per record in parallel if omitted. |
108
+
|`bulkConfirmationMessage`|`string`| Confirmation dialog text shown before the bulk action executes. |
109
+
|`bulkSuccessMessage`|`string`| Success message shown after the bulk operation. Defaults to `"N out of M items processed successfully"`. |
110
+
103
111
### Access Control
104
112
105
113
You can control who can use an action through the `allowed` function. This function receives:
@@ -130,46 +138,11 @@ The `allowed` function receives:
130
138
Return:
131
139
-`true` to allow access
132
140
-`false` to deny access
133
-
- A string with an error message to explain why access was denied
141
+
- A string with an error message to explain why access was denied — e.g. `return 'Only superadmins can perform this action'`
134
142
135
143
Here is how it looks:
136
144

137
145
138
-
139
-
You might want to allow only certain users to perform your custom bulk action.
140
-
141
-
To implement this limitation use `allowed`:
142
-
143
-
If you want to prohibit the use of bulk action for user, you can do it this way:
Instead of defining an `action` handler, you can specify a `url` that the user will be redirected to when clicking the action button:
@@ -192,7 +165,7 @@ The URL can be:
192
165
- A relative path within your admin panel (starting with '/')
193
166
- An absolute URL (starting with 'http://' or 'https://')
194
167
195
-
To open the URL in a new tab, add `?target=_blank`to the URL:
168
+
To open the URL in a new tab, append `target=_blank`as a query parameter. If the URL already has query parameters, use `&target=_blank`; otherwise use `?target=_blank`:
196
169
197
170
```ts
198
171
{
@@ -208,118 +181,12 @@ To open the URL in a new tab, add `?target=_blank` to the URL:
208
181
209
182
> ☝️ Note: You cannot specify both `action` and `url` for the same action - only one should be used.
210
183
211
-
212
-
213
-
## Custom bulk actions
214
-
215
-
You might need to give admin users a feature to perform same action on multiple records at once.
216
-
217
-
For example you might want allow setting `listed` field to `false` for multiple apartment records at once.
218
-
219
-
AdminForth by default provides a checkbox in first column of the list view for this purposes.
220
-
221
-
By default AdminForth provides only one bulk action `delete` which allows to delete multiple records at once
222
-
(if deletion for records available by [resource.options.allowedActions](/docs/api/Back/interfaces/ResourceOptions/#allowedactions))
223
-
224
-
To add custom bulk action quickly:
225
-
226
-
```ts title="./resources/apartments.ts"
227
-
//diff-add
228
-
import { AdminUser } from'adminforth';
229
-
//diff-add
230
-
import { admin } from'../index';
231
-
232
-
{
233
-
...
234
-
resourceId: 'aparts',
235
-
...
236
-
options: {
237
-
//diff-add
238
-
bulkActions: [
239
-
//diff-add
240
-
{
241
-
//diff-add
242
-
label: 'Mark as listed',
243
-
//diff-add
244
-
icon: 'flowbite:eye-solid',
245
-
//diff-add
246
-
// if optional `confirm` is provided, user will be asked to confirm action
247
-
//diff-add
248
-
confirm: 'Are you sure you want to mark all selected apartments as listed?',
const stmt =admin.resource('aparts').dataConnector.client.prepare(`UPDATE apartments SET listed = 1 WHERE id IN (${selectedIds.map(() =>'?').join(',')})`);
Action code is called on the server side only and allowed to only authorized users.
268
-
269
-
> ☝️ AdminForth provides no way to update the data, it is your responsibility to manage the data by selectedIds. You can use any ORM system
270
-
> or write raw queries to update the data.
271
-
272
-
> ☝️ You can use `adminUser` object to check whether user is allowed to perform bulk action
273
-
274
-
275
-
> Action response can return optional `successMessage` property which will be shown to user after action is performed. If this property is not provided, no messages will be shown to user.
276
-
277
-
Here is how it looks:
278
-

279
-
280
-
281
-
## Limiting access to bulk actions
282
-
283
-
You might want to allow only certain users to perform your custom bulk action.
284
-
285
-
To implement this limitation use `allowed`:
286
-
287
-
If you want to prohibit the use of bulk action for user, you can do it this way:
const stmt =admin.resource('aparts').dataConnector.client.prepare(`UPDATE apartments SET listed = 1 WHERE id IN (${selectedIds.map(() =>'?').join(',')}`);
Copy file name to clipboardExpand all lines: adminforth/documentation/docs/tutorial/08-Plugins/10-i18n.md
+21-25Lines changed: 21 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -542,37 +542,33 @@ Pluralisation rules are the same as in frontend
542
542
543
543
## Translating messages within bulk action
544
544
545
-
Label and confirm strings of bulk actions are already translated by AdminForth, but
546
-
`succesMessage` returned by action function should be translated manually because of the dynamic nature of the message.
545
+
The `label`, `bulkConfirmationMessage`, and `bulkSuccessMessage` fields of bulk actions are static strings and are translated automatically by AdminForth. However, a **dynamic** success message returned from inside `bulkHandler` must be translated manually using the `tr` helper that is injected into the handler.
547
546
548
-
Let's rework the bulk action from [bulkActions example](/docs/tutorial/Customization/Actions/#custom-bulk-actions) to use translations:
547
+
Let's rework the bulk action from the [Actions example](/docs/tutorial/Customization/Actions/#dedicated-bulk-handler) to use translations:
549
548
550
549
```tstitle="./resources/apartments.ts"
551
-
import { AdminUser } from'adminforth';
552
-
import { admin } from'../index';
553
-
554
550
{
555
-
...
556
-
resourceId: 'aparts',
557
-
...
558
-
options: {
559
-
bulkActions: [
560
-
{
561
-
label: 'Mark as listed',
562
-
icon: 'flowbite:eye-solid',
563
-
// if optional `confirm` is provided, user will be asked to confirm action
564
-
confirm: 'Are you sure you want to mark all selected apartments as listed?',
565
-
action: function ({selectedIds, adminUser }: {selectedIds:any[], adminUser:AdminUser }) {
566
-
const stmt =admin.resource('aparts').dataConnector.client.prepare(`UPDATE apartments SET listed = 1 WHERE id IN (${selectedIds.map(() =>'?').join(',')})`);
0 commit comments