Customising the refine bar
- Home
- Developing modules
- Admin controllers
- Customising the refine bar
The RefineBar
class provides the functionality which lets an operator refine the list of records displayed on the contents view in the admin interface. It looks like this:
The fields displayed above are the defaults, but you can also add additional fields to refine by, using RefineWidget
s. For example, if you had a 'type' column, you could provide a dropdown containing the valid types by using a RefineWidgetSelect
. The RefineBar is set up by the constructor of the admin controller in question. For example:
src/modules/SomeModule/Controllers/Admin/SomeAdminController.php
public function __construct() { $this->initRefineBar(); $types = Pdb::extractEnumArr($this->table_name, 'type'); $widget = new RefineWidgetSelect('type', 'Type', $types); $this->refine_bar->addWidget($widget, '='); parent::__construct(); }
The RefineWidgetAutocomplete
and RefineWidgetTextbox
classes can be used in a similar manner. When adding a widget, you can specify whether the value selected or entered must match the field value, be contained within the field, be found at the start of the field, etc. The operators available are those found in Pdb::buildClause, as follows:
Simple operators: = <= >= < > != <>
Operators for LIKE conditions; escaping of characters like % is handled automatically:
CONTAINS - generates a LIKE '%term%' condition
BEGINS - generates a LIKE 'term%' condition
ENDS - generates a LIKE '%term' condition