Forest Admin Cloud
  • What is Forest Admin?
  • How to Read This Doc?
  • Quick Start
  • Core Concepts
    • Agent
    • Data Sources
    • Collections
    • Views
    • Fields
      • Types
    • Relationships
    • Actions
    • Segments
    • Dashboards
    • Workspaces
    • Layouts
    • Roles & Permissions
    • Projects
    • Organizations
  • Native Modules
    • CRUD
    • Approval Workflows
    • Activity Logs
    • Notes
    • Inbox
  • UI Customization
    • Actions
    • Workspaces
    • Analytics
      • Metabase Integration
  • Code Customization
    • Getting Started
    • Actions
      • Context
      • Response
        • Data refresh
      • Form
        • Widgets
    • Fields
      • Filtering
      • Sorting
      • Validation
    • Relationships
    • Collections
      • Search
    • Charts
  • Security Modules
    • Roles & Permissions
    • SCIM User Provisioning
    • Single Sign On
    • Two-Factor Authentication
    • Auto-logout
    • IP Whitelisting
  • Data sources settings
    • SQL
    • MongoDB
    • Multiple Data Sources
    • Database Credentials
    • Schema Synchronization
  • Best Practices
    • Performance
Powered by GitBook
On this page
  • Emulation
  • Overriding filtering

Was this helpful?

  1. Code Customization
  2. Fields

Filtering

This is the official documentation of Forest Admin Cloud.

Emulation

To quickly make a field filterable, you can use filtering emulation. This method works best for collections with a few thousand records or less. It's a straightforward way to get started without much setup.


To make the code easier to read, all the code snippets below should be wrapped in the following code. Ensure you update the collection and field names as needed.

import type { Agent } from '@forestadmin/forest-cloud';
import { Schema } from '../typings';

export default function customizeAgent(agent: Agent<Schema>) {
  agent.customizeCollection('users', (collection) => {
    // Insert the code snippet here.
  });
}

Enabling filtering emulation for all operators

collection.emulateFieldFiltering('fullName');

Enabling filtering emulation for a single operator

collection.emulateFieldOperator('fullName', 'Equal');

Overriding filtering

The replaceFieldOperator() method can be used to improve the search capabilities by defining custom operators for filtering on fields that are not directly filterable. This method allows for the efficient performance of filtering operations based on computed fields or non-filterable fields.

collection.replaceFieldOperator('fullName', 'Equal', (value, context) => {
  const [firstName, ...lastNames] = value.split(' ');

  return {
    aggregation: 'And',
    conditions: [
      { field: 'firstName', operator: 'Equal', value: firstName },
      { field: 'lastName', operator: 'Equal', value: lastNames.join(' ') },
    ],
  };
});

To enable searching on a field, it is necessary to have at least the following operators implemented for each respective field type:

  • Number: Equal

  • Enum: Equal

  • String: IContains, Contains, or Equal

  • Uuid: Equal

Last updated 1 year ago

Was this helpful?

Using fields emulation can impact the performance of your admin panel. It is crucial to review to guarantee an optimal experience for your admin panel users.

best practices for fields