-
-
Notifications
You must be signed in to change notification settings - Fork 19
Single Search Filter
ghiscoding edited this page Dec 12, 2022
·
6 revisions
Some users might want to have 1 main single search for filtering the grid data instead of using multiple column filters. You can see a demo of that below
<form class="form-inline">
<div class="form-group">
<label>
Single Search:<br>
</label>
<select value.bind="selectedColumn"
class="form-control">
<option repeat.for="column of columnDefinitions"
model.bind="column">
${column.name}
</option>
</select>
</div>
<select value.bind="selectedOperator"
class="form-control">
<option repeat.for="operator of operatorList"
model.bind="operator">
${operator}
</option>
</select>
<input type="text"
class="form-control"
placeholder="search value"
value.bind="searchValue">
</form>
<aurelia-slickgrid grid-id="grid21"
column-definitions.bind="columnDefinitions"
grid-options.bind="gridOptions"
dataset.bind="dataset"
on-aurelia-grid-created.delegate="aureliaGridReady($event.detail)">
</aurelia-slickgrid>
export class MyExample {
@bindable() selectedColumn: Column;
@bindable() selectedOperator: string;
@bindable() searchValue: string;
aureliaGrid: AureliaGridInstance;
grid: SlickGrid;
dataView: SlickDataView;
columnDefinitions: Column[];
gridOptions: GridOption;
dataset: any[];
operatorList: OperatorString[] = ['=', '<', '<=', '>', '>=', '<>'];
aureliaGridReady(aureliaGrid: AureliaGridInstance) {
this.aureliaGrid = aureliaGrid;
}
//
// -- if any of the Search form input changes, we'll call the updateFilter() method
//
selectedOperatorChanged() {
this.updateFilter();
}
selectedColumnChanged() {
this.updateFilter();
}
searchValueChanged() {
this.updateFilter();
}
updateFilter() {
const fieldName = this.selectedColumn.field;
const filter = {};
const filterArg: FilterCallbackArg = {
columnDef: this.selectedColumn,
operator: this.selectedOperator as OperatorString, // or fix one yourself like '='
searchTerms: [this.searchValue || '']
};
if (this.searchValue) {
// pass a columnFilter object as an object which it's property name must be a column field name (e.g.: 'duration': {...} )
filter[fieldName] = filterArg;
}
this.aureliaGrid.dataView.setFilterArgs({
columnFilters: filter,
grid: this.aureliaGrid.slickGrid
});
this.aureliaGrid.dataView.refresh();
}
Contents
- Aurelia-Slickgrid Wiki
- Installation
- Styling
- Interfaces/Models
- Testing Patterns
- Column Functionalities
- Global Grid Options
- Localization
- Events
- Grid Functionalities
- Auto-Resize / Resizer Service
- Resize by Cell Content
- Add/Delete/Update or Highlight item
- Dynamically Change Row CSS Classes
- Column Picker
- Composite Editor Modal
- Context Menu
- Custom Tooltip
- Excel Copy Buffer
- Export to Excel
- Export to File (CSV/Txt)
- Grid Menu
- Grid State & Presets
- Grouping & Aggregators
- Header Menu & Header Buttons
- Header Title Grouping
- Pinning (frozen) of Columns/Rows
- Row Colspan
- Row Detail
- Row Selection
- Tree Data Grid
- SlickGrid & DataView objects
- Addons (controls/plugins)
- Backend Services