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: README.md
+38-10Lines changed: 38 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -346,25 +346,39 @@ Enable or disable lazy loading.
346
346
*`filters()[field1, field2, ...])`
347
347
Add filters to the list. Each field maps a property in the API endpoint result.
348
348
349
-
listView.filters([
349
+
customers.listView().filters([
350
350
nga.field('first_name'),
351
351
nga.field('last_name'),
352
352
nga.field('age', 'number')
353
353
]);
354
354
355
-
Filters appear when the user clicks on the "Add filter" button at the top of the list. You can also set a filter field as "pinned", to be sure it's always displayed.
355
+
Filters appear when the user clicks on the "Add filter" button at the top of the list. Once the user fills the filter widgets, the list is immediately refreshed based on the filter values, with unerlying API requests looking like:
356
+
357
+
GET /customers?first_name=XXX&last_name=XXX&age=XXX
358
+
359
+
You can also set a filter field as "pinned", to make it always visible.
356
360
357
361
listView.filters([
358
362
nga.field('q').label('Search').pinned(true)
359
363
]);
360
364
361
-
Filter fields can be of any type, including `reference` and `template`. this allows to define custom filters with ease.
365
+
Filter fields can be of any type, including `reference` and `template`. This allows to define custom filters with ease.
Add filters to the referenced results list. This can be very useful to restrict the list of possible values displayed in a dropdown list:
750
764
751
-
myView.fields([
765
+
comments.editionView().fields([
766
+
nga.field('id'),
752
767
nga.field('post_id', 'reference')
753
-
.targetEntity(post) // Select a target Entity
754
-
.targetField(nga.field('title')) // Select a label Field
755
-
.filters(function(search) {
756
-
// will send `GET /posts?title=foo%` query
768
+
.targetEntity(post)
769
+
.targetField(nga.field('title'))
770
+
.permanentFilters({
771
+
published: true
772
+
});
773
+
]);
774
+
775
+
The parameter can be be either an object or a function with a single parameter: the current search string typed by the user in the autocompletion input.
776
+
777
+
comments.editionView().fields([
778
+
nga.field('id'),
779
+
nga.field('post_id', 'reference')
780
+
.targetEntity(post)
781
+
.targetField(nga.field('title'))
782
+
.permanentFilters(function(search) {
783
+
// when the user types 'foo' in the autocompletion input
Copy file name to clipboardExpand all lines: UPGRADE-0.8.md
+30Lines changed: 30 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -96,3 +96,33 @@ nga.field('last_name')
96
96
returnvalue.toUpperCase();
97
97
});
98
98
```
99
+
100
+
## `ReferenceField.filters()` has been renamed to `ReferenceField.permanentFilters()`
101
+
102
+
When displaying a reference widget in the edition view, you can filter the list of possible values displayed in the dropdown using the `filters()` function. In 0.8, this function has been renamed to `permanentFilters()`:
103
+
104
+
```diff
105
+
nga.entity('comments').fields([
106
+
nga.field('id'),
107
+
nga.field('post_id', 'reference')
108
+
- .filters({ published: true })
109
+
+ .permanentFilters({ published: true })
110
+
]);
111
+
```
112
+
113
+
Just like the previous `filters()` feature, `permanentFilters()` also accepts a function, receiving the string typed by the user in the autocomplete field:
114
+
115
+
```diff
116
+
nga.entity('comments').fields([
117
+
nga.field('id'),
118
+
nga.field('post_id', 'reference')
119
+
- .filters(function(search) {
120
+
+ .permanentFilters(function(search) {
121
+
return search ? { q: search } : null;
122
+
});
123
+
]);
124
+
```
125
+
126
+
`filters()` will remain available until the next version, although it logs a deprecation warning in the console.
127
+
128
+
**Tip**: `permanentFilters()` now also works on the `listView`, which allows you to define a pre-filtered datagrid.
0 commit comments