Advanced Search & Column Search
Three related search surfaces: the global search box, per-column header search, and the multi-condition Advanced Search panel.
1. The simple/global search box
Every grid's toolbar has a search box that searches across all visible columns at once. How it wraps a typed term into a SQL LIKE value is customizable with search_pattern():
public function search_pattern(string $pattern): self
$pattern must contain the literal placeholder {term}, substituted with the typed term at request time. It defaults to '%{term}%' (contains).
$xcrud->search_pattern('{term}%'); // starts with, instead of contains
$xcrud->search_pattern('%{term}'); // ends with
| Parameter | Type | Default | Description |
|---|---|---|---|
$pattern | string | - | Must contain {term}. Throws otherwise. |
This only affects the simple search box and the per-column header search boxes below - the Advanced Search panel's own contains/starts-with/ends-with operators are explicit, per-condition choices there, unaffected by search_pattern().
2. Per-column header search
Each column can also show its own small search input directly under its header, letting a visitor filter by that one column specifically instead of searching every visible column at once. It's toggled on/off from the grid toolbar's ⋯ More Options menu ("Show column search") - see Grid Toolbar & the More Options Menu for the rest of what lives in that menu. The visitor's on/off choice is remembered per-browser for the session, so it doesn't need re-toggling on every page load.
Column search conditions combine with the simple search box and any Advanced Search conditions - all three narrow the result set together, they don't replace each other.
3. The Advanced Search panel
Opened from an "Advanced" button in the toolbar, this is a multi-condition filter builder: add any number of condition rows, each picking a field, an operator, and a value, then choose whether the rows combine with AND ("All conditions") or OR ("Any condition") before clicking Apply.
$xcrud = Xcrud::get_instance();
$xcrud->table('products');
$xcrud->route('advanced-search-demo');
$xcrud->columns('productCode,productName,productLine,productVendor,quantityInStock,buyPrice,MSRP');
$xcrud->change_type('buyPrice', 'price', '2', ['prefix' => '$']);
$xcrud->change_type('MSRP', 'price', '2', ['prefix' => '$']);
No extra PHP is required to enable the panel itself - it's built into every grid automatically. On this page, opening "Advanced" and combining, say, productLine = "Classic Cars" AND buyPrice > 50 narrows the result set to matching rows, independent of whatever's typed in the simple search box.
The AND/OR choice applies only to how the panel's own rows combine with each other - the panel's whole result is still ANDed against the simple search box and any permanent base filter (where()) regardless of which mode is picked.