ArtiGrid
v1.7

Advanced Filter

ArtiGrid's Advanced Filter panel renders a collapsible filter bar above the grid, giving users a rich set of controls to narrow down records without touching the inline column filters.

Each filter is declared with advancedFilter($field, $type, $options, $extra) and supports the following types: text, number, select, date, datetime, date_range, number_range, checkbox, radio, and boolean. Range types generate two inputs that produce >= and <= SQL clauses automatically.

Filters can be visually grouped with the 'group' key in the $extra array. Active filters are shown as removable chips beneath the panel header, and a badge displays the count of currently applied filters. Call renderAdvancedFilterPanel() before render() so both share the same grid ID.


<?php
    
    $grid = new ArtiGrid();
    $grid->table('consultation')
        ->advancedFilterLazy(true)
        ->advancedFilterOpen(true)
        ->template('bootstrap5')
        ->required(false)
        ->advancedFilterPosition('left')
        ->setAdvancedFilterTemplate('
            <div class="row g-3">
                <div class="col-md-12">{office}</div>
                <div class="col-md-12">{manager}</div>
                <div class="col-md-12">{name}</div>
                <div class="col-md-12">{country}</div>
                <div class="col-md-12">{region}</div>
                <div class="col-md-12">{city}</div>
            </div>
            <div class="d-flex justify-content-end mt-2">
                {export_proxy}
            </div>
        ')
        ->validation_required(['office', 'manager', 'country', 'region', 'city'])
        ->fields_arrange('office,manager,name', 'Group 1 - Names', true, true)
        ->fields_arrange('country,region,city', 'Group 2 - Regions', true, true)
        ->combobox('office', 'offices', 'officeCode', 'city')
        ->combobox('name', [
            'Pedro'   => 'Pedro',
            'Juan'    => 'Juan',
            'JHON'    => 'JHON',
            'JACKSON' => 'JACKSON',
        ])
        ->combobox('manager', 'employees', 'employeeNumber', ['firstName', 'lastName'],
            'office', 'officeCode'
        )
        ->combobox('country', 'meta_location', 'id', 'local_name', null, null, ['type' => ['=', 'CO']])
        ->combobox('region',  'meta_location', 'id', 'local_name', 'country', 'in_location', ['type' => ['=', 'RE']])
        ->combobox('city',    'meta_location', 'id', 'local_name', 'region',  'in_location', ['type' => ['=', 'CI']])

        ->advancedFilter('office', 'select',
            array_column($pdo->query("SELECT officeCode, city FROM offices ORDER BY city")->fetchAll(PDO::FETCH_ASSOC), 'city', 'officeCode'),
            ['label' => 'Office']
        )

        ->advancedFilter('manager', 'select_cascade', [], [
            'label'         => 'Manager',
            'depends_on'    => 'office',
            'table'         => 'employees',
            'value'         => 'employeeNumber',
            'label_col'     => 'firstName',
            'depends_field' => 'officeCode',
        ])
        
        ->advancedFilter('name', 'select', [
            'Pedro'   => 'Pedro',
            'Juan'    => 'Juan',
            'JHON'    => 'JHON',
            'JACKSON' => 'JACKSON',
        ], ['label' => 'Name'])

        ->advancedFilter('country', 'select',
            array_column(
                $pdo->query("SELECT id, local_name FROM meta_location WHERE type='CO' ORDER BY local_name")->fetchAll(PDO::FETCH_ASSOC),
                'local_name', 'id'
            ),
            ['label' => 'Country']
        )

        ->advancedFilter('region', 'select_cascade', [], [
            'label'         => 'Region',
            'depends_on'    => 'country',
            'table'         => 'meta_location',
            'value'         => 'id',
            'label_col'     => 'local_name',
            'depends_field' => 'in_location',
            'where'         => ['type' => ['=', 'RE']],
        ])

        ->advancedFilter('city', 'select_cascade', [], [
            'label'         => 'City',
            'depends_on'    => 'region',
            'table'         => 'meta_location',
            'value'         => 'id',
            'label_col'     => 'local_name',
            'depends_field' => 'in_location',
            'where'         => ['type' => ['=', 'CI']],
        ]);
    echo $grid->render();
?>
Advanced Filters
id name date office manager country region city Actions