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

use ForestAdmin\AgentPHP\DatasourceCustomizer\CollectionCustomizer;
use ForestAdmin\AgentPHP\DatasourceToolkit\Components\Query\ConditionTree\Operators;

$forestAgent->customizeCollection(
    'Customer',
    function (CollectionCustomizer $builder) {
        $builder->replaceFieldOperator(
        	'fullName',
        	Operators::EQUAL,
        	function ($value) {
        		[$firstName, $lastName] = explode(' ', $value);

        		return [
        			'aggregation' => 'And',
        			'conditions' => [
        				['field' => 'firstName', 'operator' => Operators::EQUAL, 'value' => $firstName],
        				['field' => 'lastName', 'operator' => Operators::EQUAL, 'value' => $lastName],
        			],
        		];
        	}
        );
    }
);
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).

use ForestAdmin\AgentPHP\DatasourceCustomizer\CollectionCustomizer;
use ForestAdmin\AgentPHP\DatasourceToolkit\Components\Query\ConditionTree\Operators;

$forestAgent->customizeCollection(
    'Customer',
    function (CollectionCustomizer $builder) {
        // Add support for all operators
    	$builder->emulateFieldFiltering('fullName');

    	// Add support for a single operator
    	$builder->emulateFieldOperator('fullName', Operators::EQUAL);
    }
);

Last updated

Was this helpful?