gp-grid-logo
Guides

Filtering

Add column filtering to the Angular grid using built-in operators, custom filter components, and live updates as users refine their search criteria today.

filterable-grid.component.ts
import { Component } from "@angular/core";
import { GpGridComponent, type ColumnDefinition } from "@gp-grid/angular";

@Component({
  selector: "app-filterable-grid",
  standalone: true,
  imports: [GpGridComponent],
  template: `
    <div style="height: 400px">
      <gp-grid
        [columns]="columns"
        [rowData]="data"
        [rowHeight]="36"
      />
    </div>
  `,
})
export class FilterableGridComponent {
  columns: ColumnDefinition[] = [
    { field: "name", cellDataType: "text", width: 150, filterable: true },
    { field: "salary", cellDataType: "number", width: 120, filterable: true },
  ];

  data = [/* your data */];
}

Custom Filter Popup

Replace the content of the filter popup with your own UI through filterRenderer. A filter renderer is an object with two keys: content renders the popup body and clear decides the clear control. The example below keeps only a search box, Cancel and Apply:

search-filter.component.ts
import { Component, input } from "@angular/core";
import type { ColumnFilterModel, FilterRendererParams } from "@gp-grid/angular";

@Component({
  selector: "app-search-filter",
  standalone: true,
  template: `
    <div class="gp-grid-filter-content">
      <input
        #search
        class="gp-grid-filter-search"
        [placeholder]="params().labels.searchPlaceholder"
        (keydown.enter)="apply(search.value)"
      />
      <div class="gp-grid-filter-buttons">
        <button type="button" (click)="params().close()">Cancel</button>
        <button type="button" class="gp-grid-filter-btn-apply" (click)="apply(search.value)">
          {{ params().labels.apply }}
        </button>
      </div>
    </div>
  `,
})
export class SearchFilterComponent {
  params = input.required<FilterRendererParams>();

  protected apply(value: string): void {
    const filter: ColumnFilterModel | null = value.trim() === "" ? null : {
      groups: [{ conditions: [{ type: "text", operator: "contains", value }], combination: "and" }],
      combination: "and",
    };
    this.params().apply(filter);
  }
}

Wrap it in an ng-template and pass the template as content:

people-grid.component.ts
@Component({
  selector: "app-people-grid",
  standalone: true,
  imports: [GpGridComponent, SearchFilterComponent],
  template: `
    <ng-template #searchFilter let-params>
      <app-search-filter [params]="params" />
    </ng-template>
    <gp-grid [columns]="columns" [rowData]="data" [rowHeight]="36" />
  `,
})
export class PeopleGridComponent implements AfterViewInit {
  @ViewChild("searchFilter", { static: true }) searchFilter!: FilterContentTemplate;
  protected columns: AngularColumnDefinition[] = [];
  private readonly cdr = inject(ChangeDetectorRef);

  ngAfterViewInit(): void {
    this.columns = [
      {
        field: "bio",
        cellDataType: "text",
        width: 260,
        filterRenderer: { content: this.searchFilter, clear: "default" }, 
      },
    ];
    this.cdr.detectChanges();
  }
}

A column can also reference a key of the [filterRenderers] registry, and [filterRenderer] sets a renderer for every filterable column. A column's own renderer wins, then the grid-wide one, then the built-in content. Only templates are rendered: a definition built from functions is ignored.

Clear Control

clear is a required key, so removing the way to clear a filter is always a deliberate choice. Omitting it is a type error.

ValueResult
"default"The grid's Clear button, labelled with labels.clear
FilterClearTemplate (context FilterClearParams)Your own control, rendered by the grid under the content
nullNo clear control

The clear control is placed inside .gp-grid-filter-clear, styled with :where so you can override it.

Filter Renderer Parameters

content receives FilterRendererParams:

PropertyTypeDescription
columnColumnDefinitionColumn definition
columnIdstringNormalized identity: colId ?? field
currentFilterColumnFilterModel | undefinedThe column's active filter
distinctValuesCellValue[]Distinct values; filled for text, boolean and object columns, empty otherwise
labelsGridLabelsResolved grid labels
apply(filter: ColumnFilterModel | null) => voidSet the filter (null clears it) and close the popup
close() => voidClose the popup without changing the filter

A custom clear control receives FilterClearParams:

PropertyTypeDescription
clear() => voidClear the column's filter and close the popup
hasFilterbooleanWhether the column has an active filter
labelsGridLabelsResolved grid labels

The grid keeps the popup's position, title, Escape and click-outside handling. The content is recreated when the popup moves to another column, so its local state starts fresh. Strings your content adds itself, such as "Cancel", are yours to localize: GridLabels only covers the grid's own controls. Types: AngularFilterRenderer, FilterContentTemplate, FilterClearTemplate.

Grouped Conditions

The condition editor makes Boolean precedence explicit. Conditions live inside group cards: one AND/OR selector joins the conditions in a group, while a separate selector joins the groups themselves.

  • Use Add condition to extend the current group.
  • Use Add group to create a separate branch.
  • Empty conditions and groups are discarded when you apply the filter.

This means the popup can distinguish (A AND B) OR C from A AND (B OR C). The first expression is represented as:

import type { ColumnFilterModel } from "@gp-grid/angular";

const filter: ColumnFilterModel = {
  groups: [
    {
      conditions: [
        { type: "text", operator: "startsWith", value: "A" },
        { type: "text", operator: "endsWith", value: "z" },
      ],
      combination: "and",
    },
    {
      conditions: [
        { type: "text", operator: "equals", value: "Giovanni" },
      ],
      combination: "and",
    },
  ],
  combination: "or",
};

ColumnFilterModel.combination joins groups. Each FilterConditionGroup.combination joins the conditions inside that group. Filters belonging to different columns are combined with AND at row level.

Migrating Flat Condition Models

The component's GridCore.setFilter() still accepts the previous flat model with conditions, combination, and optional per-condition nextOperator properties. It preserves the old left-to-right result and normalizes it into equivalent groups. The grid's filter state and server-side DataSourceRequest.filter always use the grouped shape.

Use normalizeColumnFilterModel(legacyFilter) when you want to migrate stored filter state explicitly.