Skip to content

Commit 03b926f

Browse files
committed
docs: update docs for the foreign inline list
1 parent 1e81e91 commit 03b926f

File tree

1 file changed

+89
-2
lines changed

1 file changed

+89
-2
lines changed

adminforth/documentation/docs/tutorial/07-Plugins/03-ForeignInlineList.md

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,96 @@ Add to your `'adminuser'` resource configuration the plugin instance:
7272
}
7373
```
7474

75-
You can use `modifyTableResourceConfig` callback to modify what columns to show in the list and filter of the foreign table.
75+
You can use the `modifyTableResourceConfig` callback to modify which columns to show in the list and filter of the foreign table.
7676

7777
![alt text](ForeignInlineList.png)
7878

7979
> 👆 To make plugin work, the specified resource (defined with `foreignResourceId`) should have one (and only one) column that refers to the current resource on which you add a plugin.
80-
> In our case we add plugin to `adminuser` resource, so the `aparts` resource should have one column with `foreignResource.resourceId` equal to `adminuser` resourceId.
80+
> In our case we add plugin to `adminuser` resource, so the `aparts` resource should have one column with `foreignResource.resourceId` equal to `adminuser` resourceId.
81+
82+
## Default filters
83+
84+
If you need to add default filters for the foreign resource based on your current record (for example show apartment only from Italy, when user have country Italy), you can use defaultFilters callback:
85+
>👆 This example won't work until you'll add counrty field in your adminuser resource and it's only for demonstrating concept of callback
86+
87+
```ts title="./resources/adminuser.ts"
88+
89+
...
90+
91+
new ForeignInlineListPlugin({
92+
93+
...
94+
//diff-add
95+
defaultFilters: (record: any) => {
96+
//diff-add
97+
return [
98+
//diff-add
99+
{
100+
//diff-add
101+
field: "country",
102+
//diff-add
103+
operator: AdminForthFilterOperators.EQ,
104+
//diff-add
105+
value: record.country,
106+
//diff-add
107+
}
108+
//diff-add
109+
]
110+
//diff-add
111+
}
112+
113+
...
114+
115+
})
116+
117+
...
118+
119+
```
120+
121+
>👆It also makes sense to modify the table resource and hide the country field from filters, because this value is hardcoded and equals the country from the record:
122+
123+
124+
```ts
125+
126+
...
127+
128+
new ForeignInlineListPlugin({
129+
130+
...
131+
132+
//diff-add
133+
modifyTableResourceConfig: (resourceConfig: AdminForthResource) => {
134+
//diff-add
135+
const column = resourceConfig.columns.find((c: AdminForthResourceColumn) => c.name === 'country')!.showIn = {
136+
//diff-add
137+
list: true,
138+
//diff-add
139+
show: true,
140+
//diff-add
141+
edit: true,
142+
//diff-add
143+
create: true,
144+
//diff-add
145+
filter: false
146+
//diff-add
147+
};
148+
//diff-add
149+
},
150+
151+
defaultFilters: (record: any) => {
152+
return [
153+
{
154+
field: "country",
155+
operator: AdminForthFilterOperators.EQ,
156+
value: record.country,
157+
}
158+
]
159+
}
160+
161+
...
162+
163+
})
164+
165+
...
166+
167+
```

0 commit comments

Comments
 (0)