Skip to content

Commit 5f7305c

Browse files
AstaldosPetr Kachanovsky
andauthored
docs: add afterDatasourceResponse section (#82)
Co-authored-by: Petr Kachanovsky <[email protected]>
1 parent beddfbb commit 5f7305c

File tree

1 file changed

+28
-0
lines changed
  • adminforth/documentation/docs/tutorial/03-Customization

1 file changed

+28
-0
lines changed

adminforth/documentation/docs/tutorial/03-Customization/04-hooks.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,34 @@ For example we can prevent the user to see Apartments created by other users. Su
155155
This hook will prevent the user to see Apartments created by other users in list, however if user will be able to discover
156156
the apartment id, he will be able to use show page to see the apartment details, that is why separate limiting for show page is required as well. Below we will discover how to limit access to show page.
157157

158+
### Modify record after it is returned from database
159+
160+
You can also change resource data after it was loaded.
161+
162+
For example, you can change the way columns value is displayed by changing the value itself:
163+
164+
```ts title='./resources/apartments.ts'
165+
{
166+
...
167+
hooks: {
168+
list: {
169+
//diff-add
170+
afterDatasourceResponse: async ({ response }: { response: any }) => {
171+
//diff-add
172+
response.forEach((r: any) => {
173+
//diff-add
174+
r.price = `$${r.price}`;
175+
//diff-add
176+
});
177+
//diff-add
178+
return { ok: true, error: "" };
179+
//diff-add
180+
},
181+
},
182+
},
183+
}
184+
```
185+
158186
### Dropdown list of foreignResource
159187

160188
By default if there is `foreignResource` like we use for demo on `realtor_id` column, the filter will suggest a

0 commit comments

Comments
 (0)