Filters

Add filters on a crud in the configure function. Internally, this uses an EnsoSelectField, so pass everything as you normally would in a props value. Note: As this does not pass through SelectField.php, the standard helpers wont work. For example, you'll have to translate useAjax(route(), Item::query) into is base value: settings['ajax_url'] (the query part is reduntant at his point, it's used to populating the form from an item).

->filters([
    'form' => [
        'type' => 'text'
        'label' => 'Form',
        'default' => null,
        'props' => [
            'settings' => [
                'ajax_url' => route('admin.users.search'),
                ...
            ],
        ],
        'classes' => 'is-4',
        'callable' => [callable],
    ],
])

The index for each filter item is the key you want to send data back as for filtering in the backend.

  • type : The type of filter input. 'text', 'select', 'checkbox' or 'date'.
  • label : The label that the filter should use. Setting this to an empty string means no label
  • default : The initial value that this filter should hold
  • props : Any Props that you might normally apply have applied by a SelectField
  • classes : A string of classes to add to the filterItem. Default is is-4
  • callable: Special case filtering.

    This is used in the controller to determine how the value should be used instead of the default action for the given type. Current types and their defaults:

    • text: $name LIKE %{$value}%
    • select: $name = $value
    • checkbox: $name = $value - This assumes truthy value. Will currently not work out-the-box with checkbox groups.
    • date: $name >= $value - Initial purpose: 'Created Since'

API:

/**
 * Helper method for setting/getting item filters
 *
 * @param null|array $filters
 * @return self|array
 */
public function filters($filters = null)
/**
 * Boolean check to see whether any Filters are available for this config
 *
 * @return boolean
 */
(bool) hasItemFilters()
/**
 * Returns the Filters list
 *
 * @return array
 */
(array) getItemFilters()
/**
 * Overwrites the entire Filters array.
 *
 * @param array $item_filters
 *
 * @return self
 */
(self) setItemFilters($item_filters)
/**
 * Adds a named Filter to the list.
 *
 * @param string $name
 * @param array $item_filters
 *
 * @return self
 */
(self) addItemFilter($name, $item_filter)
/**
 * Adds a set of Filters to the Filters list
 *
 * @param array $item_filters
 *
 * @return self
 */
(self) addItemFilters($item_filters)
/**
 * Gets a filter by it's name
 *
 * @param string $filter_name
 *
 * @return array
 */
(self) getFilterByName($filter_name)
/**
 * Removes a selection from the Filters list, by name
 *
 * @param string $name
 *
 * @return self
 */
(self) removeItemFilter($name)