Filter

Definition

A filter is used to define the appearance of the content of the table in the list view. It allows you to configure the list of columns to display by default, their order, the search conditions to apply, the sort order and for which type of view you want to use it (List or Related List).

Examples

Default filter

<?php

use Uccello\Core\Models\Filter;
use Uccello\Core\Models\Module;

...

$module = Module::where('name', 'person')->first();

Filter::create([
    'module_id' => $module->id,
    'domain_id' => null,
    'user_id' => null,
    'name' => 'filter.all',
    'type' => 'list',
    'columns' => [ 'first_name', 'last_name', 'birthday', 'city' ],
    'conditions' => null,
    'order' => null,
    'is_default' => true,
    'is_public' => false,
    'data' => [ 'readonly' => true ],
]);

This filter is the default one for the list view of the Person module. Its label filter.all will be replaced in the UI by its translation : All. It displays by default the columns first_name, last_name, birthday and city. As domain_id and user_id are null, this filter is available in all domains, for all users. As readonly is true, this filter cannot be deleted from the UI.

If no specific filters are defined for Related List, this filter will be used by default.

Custom filter for List View

<?php

use Uccello\Core\Models\Filter;
use Uccello\Core\Models\Module;

...

$module = Module::where('name', 'person')->first();

Filter::create([
    'module_id' => $module->id,
    'domain_id' => 1,
    'user_id' => 3,
    'name' => 'People called John',
    'type' => 'list',
    'columns' => [ 'first_name', 'last_name', 'birthday' ],
    'conditions' => [ 
        "search"  => [
            "first_name" => "John"
        ]
    ],
    'order' => [ 'last_name' => 'asc' ],
    'is_default' => false,
    'is_public' => true,
    'data' => null,
]);

This filter is a custom one available only in the domain with the id 1. It is available for the user with the id 3, but as is_public is true, this filter is also visible by the others users. Its name is People called John. It will display like that in the UI, independently of the selected language. It displays by default the columns first_name, last_name and birthday. It will only display records whose first_name field contains John. The results will be sorted by last_name in ascending order.

<?php

use Uccello\Core\Models\Filter;
use Uccello\Core\Models\Module;

...

$module = Module::where('name', 'person')->first();

Filter::create([
    'module_id' => $module->id,
    'domain_id' => null,
    'user_id' => null,
    'name' => 'filter.related-list',
    'type' => 'related-list',
    'columns' => [ 'first_name', 'last_name' ],
    'conditions' => null,
    'order' => [ 'last_name' => 'asc' ],
    'is_default' => false,
    'is_public' => false,
    'data' => null,
]);

It could be useful to create specific filters for Related List to display different columns from those in the List View. To do this you just set related-list for the type of filter.

Properties

Last updated