Filtering
Disabling filtering
Disable filtering without any code in the field settings in the Forest UI. That setting only hides the filter in the UI: the API still accepts filters on the field. Use the method below to make the back-end reject them too.
disableFieldFiltering method removes filtering for end users on a column, or on a many-to-one or one-to-one relationship. It needs @forestadmin/agent 1.107.0 or later, or forest_admin_rails 1.45.0 or later.
author disabled, the back-end rejects a filter on author:name.
Your customizations keep filtering on the field:
- A disabled column remains usable as the key of a custom relationship.
- Code segments keep filtering on a disabled column or through a disabled relationship.
- The search bar keeps reading a disabled column, and searching through a disabled relationship.
- The method accepts a column, a many-to-one or a one-to-one relationship. On a primary key, a one-to-many or many-to-many relationship, or a polymorphic relationship, the back-end fails to start.
- Disabling a many-to-one relationship leaves its foreign key filterable: with
authordisabled, users still filter onauthorId. Disable the foreign key too to remove both. - Pass the field’s original name. On a field renamed with
renameField(Node.js) orrename_field(Ruby), use the name it had before the renaming.
Substitution
Operation substitution serves two purposes:- Performance: provide a more efficient way to perform a given filtering operation
- Capabilities: enable filtering on a computed field or other non-filterable fields
Operators to support to enable search
Use the
replaceFieldOperator method to unlock the operators.
Emulation
Filtering emulation allows making fields filterable automatically. It is a convenient way to get things working quickly for collections that have a low number of records (in the thousands at most).Sorting
Depending on the data source, not all fields may be sortable, or you may want to change how the native sorting works. Use thereplaceFieldSorting and emulateFieldSorting methods to change a single column’s sorting behavior.
Substitution
Provide replacement sort clauses. In this example, we’re telling Forest “When a user sorts by full name, I want to sort by the last name, and then by the first name”.creationDate is equivalent to sorting by the primary key in reverse order.
Using sort substitution where needed can save you from adding many indexes to your database.