Override filtering behavior

You may want to read about the following topics before using those features:

Disabling operators

Disabling filtering can be made without any code in the field settings ↗.

Substitution

Operation substitution can be used for two motives:

  • Performance: provide a more efficient way to perform a given filtering operation

  • Capabilities: enable filtering on a computed field or other non-filterable fields

Traditional Syntax

Using full context methods with customize_collection:

include ForestAdmin::Types

@create_agent.customize_collection('customer') do |collection|
  collection.replace_field_operator('fullName', Operators::EQUAL) do |value|
    first_name, *last_names = value.split(' ')

    ConditionTreeBranch.new(
      'And',
      [
        ConditionTreeLeaf.new('firstName', Operators::EQUAL, first_name),
        ConditionTreeLeaf.new('lastName', Operators::EQUAL, last_names.join(' ')),
      ]
    )
  end
end

DSL Syntax

Using simplified DSL with collection:

Column Type
Operator to support

Number

Equal

Enum

Equal

String

IContains OR Contains OR Equal

Uuid

Equal

You can 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).

Traditional Syntax

Using full context methods with customize_collection:

DSL Syntax

Using simplified DSL with collection:

Last updated

Was this helpful?