📕
Angular-Slickgrid
Live DemoGitHub
  • Introduction
  • Getting Started
    • Quick start
    • Troubleshooting
  • Styling
    • Dark Mode
    • Styling CSS/SASS/Themes
  • Column Functionalities
    • Cell Menu (Action Menu)
    • Editors
      • Autocomplete
      • Date Picker (vanilla-calendar)
      • LongText (textarea)
      • Select Dropdown Editor (single/multiple)
    • Filters
      • Autocomplete
      • Input Filter (default)
      • Select Filter (dropdown)
      • Compound Filters
      • Range Filters
      • Custom Filter
      • Styling Filled Filters
      • Single Search Filter
    • Formatters
    • Sorting
  • Events
    • Available events
    • On Events
  • Slick Grid/DataView Objects
    • Slick Grid/DataView Objects
  • Grid Functionalities
    • Auto-Resize / Resizer Service
    • Resize by Cell Content
    • Column Picker
    • Composite Editor Modal
    • Custom Tooltip
    • Add, Update or Highlight a Datagrid Item
    • Dynamically Add CSS Classes to Item Rows
    • Column & Row Spanning
    • Context Menu
    • Custom Footer
    • Excel Copy Buffer Plugin
    • Export to Excel
    • Export to File (csv/txt)
    • Grid Menu
    • Grid State & Presets
    • Grouping & Aggregators
    • Header & Footer Slots
    • Header Menu & Header Buttons
    • Infinite Scroll
    • Pinning (frozen) of Columns/Rows
    • Providing data to the grid
    • Row Detail
    • Row Selection
    • Tree Data Grid
    • Row Based Editing Plugin
    • FAQ
  • Developer Guides
    • CSP Compliance
  • Localization
    • with Custom Locales
    • with ngx-translate
      • Component Sample
  • Backend Services
    • Custom Backend Service
    • OData
    • GraphQL
      • JSON Result Structure
      • Filtering Schema
      • Pagination Schema
      • Sorting Schema
  • Testing
    • Testing Patterns
  • Migrations
    • Migration Guide to 2.x (2018-06-23)
    • Migration Guide to 3.x (2021-07-20)
    • Migration Guide to 4.x (2021-12-11)
    • Migration Guide to 5.x (2022-10-17)
    • Migration Guide to 6.x (2023-05-29)
    • Migration Guide to 7.x (2023-12-15)
    • Migration Guide to 8.x (2024-05-23)
    • Migration Guide to 9.x (2025-05-10)
Powered by GitBook
On this page
Edit on GitHub
  1. Column Functionalities
  2. Filters

Single Search Filter

PreviousStyling Filled FiltersNextFormatters

Last updated 26 days ago

Index

Description

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

Code Sample

View

<angular-slickgrid gridId="grid23" [columns]="columnDefinitions" [options]="gridOptions"
   [dataset]="dataset" (onAngularGridCreated)="angularGridReady($event.detail)">
</angular-slickgrid>

<form class="form-inline">
    <div class="form-group">
        <label>Single Search: </label>
        <select class="form-control" name="selectedColumn" [(ngModel)]="selectedColumn"
            (ngModelChange)="updateFilter()">
            <option [ngValue]="field" *ngFor="let field of columnDefinitions">{{field.name}}</option>
        </select>
        <select class="form-control" name="selectedOperator" [(ngModel)]="selectedOperator"
            (ngModelChange)="updateFilter()">
            <option [ngValue]="operator" *ngFor="let operator of operatorList">{{operator}}</option>
            </select>

        <input type="text" class="form-control" name="searchValue" placeholder="search value" autocomplete="off"
                (input)="updateFilter()" [(ngModel)]="searchValue">
    </div>
</form>

ViewModel

export class MyComponent {
  angularGrid: AngularGridInstance;
  grid: any;
  dataView: any;
  columnDefinitions: Column[];
  gridOptions: GridOption;
  dataset: any[];
  operatorList: OperatorString[] = ['=', '<', '<=', '>', '>=', '<>'];
  selectedOperator = '=';
  searchValue = '';
  selectedColumn: Column;

  angularGridReady(angularGrid: AngularGridInstance) {
    this.angularGrid = angularGrid;
  }

  updateFilter() {
    if (this.selectedColumn && this.selectedOperator) {
      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.angularGrid.dataView.setFilterArgs({
        columnFilters: filter,
        grid: this.angularGrid.slickGrid
      });
      this.angularGrid.dataView.refresh();
    }
  }
}

Sample

2019-04-16_15-42-05
Update Filters Dynamically
Custom Filter Predicate