This section describes the grid options that configure the Advanced Filter input, where it is displayed, and the Advanced Filter Builder.
Advanced Filter Input Copy Link
The buttons shown in the Advanced Filter input and the element it is displayed in can both be configured.
Buttons Copy Link
It is possible to customise the buttons displayed in the Advanced Filter, allowing for the use of other Filter Buttons such as Reset, Cancel and Clear. Configure via the grid option advancedFilterParams which follows the IAdvancedFilterParams interface:
Specifies the buttons to be shown in the Advanced Filter, in the order they should be displayed in. The options are: 'apply': The Apply button will apply the filter. 'clear': The Clear button will clear the filter input without removing the current active filter. 'reset': The Reset button will clear the filter and apply an empty filter. 'cancel': The Cancel button will discard any changes that have been made to the filter in the UI, restoring the applied model. |
Whether to hide the Builder button to open the Advanced Filter Builder |
The following example demonstrates configuring the Advanced Filter:
- The
Builderbutton has been removed viasuppressBuilderButton. The Builder can still be opened via the API. - The
buttonshave been configured to add the Clear and Reset buttons.
import { Component } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { AgGridAngular } from "ag-grid-angular";
import {
AdvancedFilterModel,
ClientSideRowModelModule,
ColDef,
ColGroupDef,
GridApi,
GridOptions,
GridReadyEvent,
GridState,
GridStateModule,
IAdvancedFilterParams,
ModuleRegistry,
NumberFilterModule,
TextFilterModule,
enableDevValidations,
} from "ag-grid-community";
import {
AdvancedFilterModule,
ColumnMenuModule,
ContextMenuModule,
} from "ag-grid-enterprise";
if (process.env.NODE_ENV !== "production") {
// Enable extended validations only for development
enableDevValidations();
}
ModuleRegistry.registerModules([
TextFilterModule,
NumberFilterModule,
GridStateModule,
AdvancedFilterModule,
ClientSideRowModelModule,
ColumnMenuModule,
ContextMenuModule,
]);
import { IOlympicData } from "./interfaces";
@Component({
selector: "my-app",
standalone: true,
imports: [AgGridAngular],
template: `<ag-grid-angular
style="width: 100%; height: 100%;"
[advancedFilterParams]="advancedFilterParams"
[columnDefs]="columnDefs"
[defaultColDef]="defaultColDef"
[enableAdvancedFilter]="true"
[initialState]="initialState"
[rowData]="rowData"
(gridReady)="onGridReady($event)"
/> `,
})
export class AppComponent {
advancedFilterParams: IAdvancedFilterParams = {
buttons: ["clear", "apply", "reset"],
suppressBuilderButton: true,
};
columnDefs: ColDef[] = [
{ field: "athlete" },
{ field: "country" },
{ field: "sport" },
{ field: "age", minWidth: 100 },
{ field: "gold", minWidth: 100 },
{ field: "silver", minWidth: 100 },
{ field: "bronze", minWidth: 100 },
];
defaultColDef: ColDef = {
flex: 1,
minWidth: 180,
filter: true,
};
initialState: GridState = {
filter: {
advancedFilterModel: initialAdvancedFilterModel,
},
};
rowData!: IOlympicData[];
constructor(private http: HttpClient) {}
onGridReady(params: GridReadyEvent<IOlympicData>) {
this.http
.get<
IOlympicData[]
>("https://www.ag-grid.com/example-assets/olympic-winners.json")
.subscribe((data) => (this.rowData = data));
}
}
const initialAdvancedFilterModel: AdvancedFilterModel = {
filterType: "join",
type: "AND",
conditions: [
{
filterType: "join",
type: "OR",
conditions: [
{
filterType: "number",
colId: "age",
type: "greaterThan",
filter: 23,
},
{
filterType: "text",
colId: "sport",
type: "endsWith",
filter: "ing",
},
],
},
{
filterType: "text",
colId: "country",
type: "contains",
filter: "united",
},
],
};
import '@angular/compiler';
import { provideHttpClient } from '@angular/common/http';
import { enableProdMode } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
if (new URLSearchParams(window.location.search).get('prod') !== 'false') {
enableProdMode();
}
const app = bootstrapApplication(AppComponent, {
providers: [provideHttpClient()],
});
export interface IOlympicData {
athlete: string,
age: number,
country: string,
year: number,
date: string,
sport: string,
gold: number,
silver: number,
bronze: number,
total: number
} Filter Parent Copy Link
By default the Advanced Filter is displayed underneath the Column Headers. To display the Advanced Filter outside of the grid (such as above it), set the grid option advancedFilterParent. The Popup Parent must also be set to an element that contains both the Advanced Filter parent and the grid.
DOM element to use as the parent for the Advanced Filter to allow it to appear outside of the grid.
Set to null or undefined to appear inside the grid. |
The following example demonstrates displaying the Advanced Filter outside of the grid:
- The Advanced Filter parent is set using an element directly above the grid.
- Popup Parent is set to the document body.
import { Component } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { AgGridAngular } from "ag-grid-angular";
import "./styles.css";
import {
ClientSideRowModelModule,
ColDef,
ColGroupDef,
GridApi,
GridOptions,
GridReadyEvent,
ModuleRegistry,
NumberFilterModule,
TextFilterModule,
enableDevValidations,
} from "ag-grid-community";
import {
AdvancedFilterModule,
ColumnMenuModule,
ContextMenuModule,
} from "ag-grid-enterprise";
if (process.env.NODE_ENV !== "production") {
// Enable extended validations only for development
enableDevValidations();
}
ModuleRegistry.registerModules([
TextFilterModule,
NumberFilterModule,
AdvancedFilterModule,
ClientSideRowModelModule,
ColumnMenuModule,
ContextMenuModule,
]);
import { IOlympicData } from "./interfaces";
@Component({
selector: "my-app",
standalone: true,
imports: [AgGridAngular],
template: `<div id="wrapper" class="example-wrapper">
<div id="advancedFilterParent" class="example-header"></div>
<ag-grid-angular
style="width: 100%; height: 100%;"
[columnDefs]="columnDefs"
[defaultColDef]="defaultColDef"
[enableAdvancedFilter]="true"
[popupParent]="popupParent"
[rowData]="rowData"
(gridReady)="onGridReady($event)"
/>
</div> `,
})
export class AppComponent {
columnDefs: ColDef[] = [
{ field: "athlete" },
{ field: "country" },
{ field: "sport" },
{ field: "age", minWidth: 100 },
{ field: "gold", minWidth: 100 },
{ field: "silver", minWidth: 100 },
{ field: "bronze", minWidth: 100 },
];
defaultColDef: ColDef = {
flex: 1,
minWidth: 180,
filter: true,
};
popupParent: HTMLElement | null = document.body;
rowData!: IOlympicData[];
constructor(private http: HttpClient) {}
onGridReady(params: GridReadyEvent<IOlympicData>) {
// could also be provided via grid option `advancedFilterParent`
params.api.setGridOption(
"advancedFilterParent",
document.getElementById("advancedFilterParent"),
);
this.http
.get<
IOlympicData[]
>("https://www.ag-grid.com/example-assets/olympic-winners.json")
.subscribe((data) => (this.rowData = data));
}
}
.example-wrapper {
display: flex;
flex-direction: column;
height: 100%;
padding-left: 5px;
}
#myGrid {
flex: 1 1 0px;
width: 100%;
}
.example-header {
margin-bottom: 10px;
}
import '@angular/compiler';
import { provideHttpClient } from '@angular/common/http';
import { enableProdMode } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
if (new URLSearchParams(window.location.search).get('prod') !== 'false') {
enableProdMode();
}
const app = bootstrapApplication(AppComponent, {
providers: [provideHttpClient()],
});
export interface IOlympicData {
athlete: string,
age: number,
country: string,
year: number,
date: string,
sport: string,
gold: number,
silver: number,
bronze: number,
total: number
} Advanced Filter Builder Copy Link
The Advanced Filter Builder can be configured via the grid option advancedFilterBuilderParams which follows the IAdvancedFilterBuilderParams interface:
Width in pixels of the Advanced Filter Builder add button select popup. |
Specifies the buttons to be shown in the Advanced Filter Builder, in the order they should be displayed in. The options are: 'apply': The Apply button will apply the filter and close the builder. 'clear': The Clear button will clear the filter in the builder without removing the current active filter. 'reset': The Reset button will clear the filter and apply an empty filter. 'cancel': The Cancel button will discard any changes that have been made to the filter in the UI, and close the Builder without applying any changes. |
Minimum width in pixels of the Advanced Filter Builder popup. |
Max width in pixels of the Advanced Filter Builder pill select popup. Unset, the popup grows to its widest option, bounded by the width of the Advanced Filter Builder.
|
Min width in pixels of the Advanced Filter Builder pill select popup. |
Whether to show the move up and move down buttons in the Advanced Filter Builder. |
Whether to hide the Full Screen button in the Advanced Filter Builder. |
Launch via API Copy Link
As well as using the button in the Advanced Filter, it's possible to launch the Advanced Filter Builder via the showAdvancedFilterBuilder grid API method, and hide it via hideAdvancedFilterBuilder:
Open the Advanced Filter Builder dialog (if enabled). |
Closes the Advanced Filter Builder dialog (if enabled).
Un-applied changes are discarded. |
Events Copy Link
When the Advanced Filter Builder is shown or hidden, the advancedFilterBuilderVisibleChanged event is fired:
Advanced Filter Builder visibility has changed (opened or closed). |
The following example demonstrates configuring the Advanced Filter Builder:
- The
Advanced Filter Builderbutton displays the Advanced Filter Builder via the API methodshowAdvancedFilterBuilder. - The
advancedFilterBuilderVisibleChangedevent is used to toggle the disabled status of theAdvanced Filter Builderbutton. - The
showMoveButtonsparam is set in theadvancedFilterBuilderParams, which displays buttons allowing the filter rows to be moved up and down (including via keyboard navigation).
import { Component } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { AgGridAngular } from "ag-grid-angular";
import "./styles.css";
import {
AdvancedFilterBuilderVisibleChangedEvent,
AdvancedFilterModel,
ClientSideRowModelModule,
ColDef,
ColGroupDef,
GridApi,
GridOptions,
GridReadyEvent,
GridState,
GridStateModule,
IAdvancedFilterBuilderParams,
ModuleRegistry,
NumberFilterModule,
TextFilterModule,
enableDevValidations,
} from "ag-grid-community";
import {
AdvancedFilterModule,
ColumnMenuModule,
ContextMenuModule,
} from "ag-grid-enterprise";
if (process.env.NODE_ENV !== "production") {
// Enable extended validations only for development
enableDevValidations();
}
ModuleRegistry.registerModules([
TextFilterModule,
NumberFilterModule,
GridStateModule,
AdvancedFilterModule,
ClientSideRowModelModule,
ColumnMenuModule,
ContextMenuModule,
]);
import { IOlympicData } from "./interfaces";
@Component({
selector: "my-app",
standalone: true,
imports: [AgGridAngular],
template: `<div id="wrapper" class="example-wrapper">
<div class="example-header">
<div id="advancedFilterParent" class="parent"></div>
<button id="advancedFilterBuilderButton" (click)="showBuilder()">
Advanced Filter Builder
</button>
<i id="advancedFilterIcon" class="fa fa-filter filter-icon"></i>
</div>
<ag-grid-angular
style="width: 100%; height: 100%;"
[advancedFilterBuilderParams]="advancedFilterBuilderParams"
[columnDefs]="columnDefs"
[defaultColDef]="defaultColDef"
[enableAdvancedFilter]="true"
[popupParent]="popupParent"
[initialState]="initialState"
[rowData]="rowData"
(advancedFilterBuilderVisibleChanged)="
onAdvancedFilterBuilderVisibleChanged($event)
"
(filterChanged)="onFilterChanged($event)"
(gridReady)="onGridReady($event)"
/>
</div> `,
})
export class AppComponent {
private gridApi!: GridApi<IOlympicData>;
advancedFilterBuilderParams: IAdvancedFilterBuilderParams = {
showMoveButtons: true,
suppressFullScreenButton: true,
buttons: ["clear", "apply", "cancel"],
};
columnDefs: ColDef[] = [
{ field: "athlete" },
{ field: "country" },
{ field: "sport" },
{ field: "age", minWidth: 100 },
{ field: "gold", minWidth: 100 },
{ field: "silver", minWidth: 100 },
{ field: "bronze", minWidth: 100 },
];
defaultColDef: ColDef = {
flex: 1,
minWidth: 180,
filter: true,
};
popupParent: HTMLElement | null = document.getElementById("wrapper");
initialState: GridState = {
filter: {
advancedFilterModel: initialAdvancedFilterModel,
},
};
rowData!: IOlympicData[];
constructor(private http: HttpClient) {}
onAdvancedFilterBuilderVisibleChanged(
event: AdvancedFilterBuilderVisibleChangedEvent<IOlympicData>,
) {
const eButton = document.getElementById("advancedFilterBuilderButton")!;
if (event.visible) {
eButton.setAttribute("disabled", "");
} else {
eButton.removeAttribute("disabled");
}
}
onFilterChanged() {
const advancedFilterApplied = !!this.gridApi.getAdvancedFilterModel();
document
.getElementById("advancedFilterIcon")!
.classList.toggle("filter-icon-disabled", !advancedFilterApplied);
}
showBuilder() {
this.gridApi.showAdvancedFilterBuilder();
}
onGridReady(params: GridReadyEvent<IOlympicData>) {
this.gridApi = params.api;
// An external parent hides the input in the grid, so the filter is edited only via the Builder.
params.api.setGridOption(
"advancedFilterParent",
document.getElementById("advancedFilterParent"),
);
this.http
.get<
IOlympicData[]
>("https://www.ag-grid.com/example-assets/olympic-winners.json")
.subscribe((data) => (this.rowData = data));
}
}
const initialAdvancedFilterModel: AdvancedFilterModel = {
filterType: "join",
type: "AND",
conditions: [
{
filterType: "join",
type: "OR",
conditions: [
{
filterType: "number",
colId: "age",
type: "greaterThan",
filter: 23,
},
{
filterType: "text",
colId: "sport",
type: "endsWith",
filter: "ing",
},
],
},
{
filterType: "text",
colId: "country",
type: "contains",
filter: "united",
},
],
};
.example-wrapper {
display: flex;
flex-direction: column;
height: 100%;
}
#myGrid {
flex: 1 1 0px;
width: 100%;
}
.example-header {
margin-bottom: 10px;
}
.parent {
display: none;
}
.filter-icon {
margin-left: 4px;
opacity: 0.6;
}
.filter-icon-disabled {
display: none;
}
import '@angular/compiler';
import { provideHttpClient } from '@angular/common/http';
import { enableProdMode } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
if (new URLSearchParams(window.location.search).get('prod') !== 'false') {
enableProdMode();
}
const app = bootstrapApplication(AppComponent, {
providers: [provideHttpClient()],
});
export interface IOlympicData {
athlete: string,
age: number,
country: string,
year: number,
date: string,
sport: string,
gold: number,
silver: number,
bronze: number,
total: number
} Localisation Copy Link
If providing custom Localisation values for the Advanced Filter, note that if the filter option values contain spaces, one option value cannot start with another option value.