I want to modify the filter logic for a column in Angular Ag-Grid. What I mean by this is for example, I feed in a value which is unrelated to the column to the filter. The filter would then be able interpret that value and do some actions based off it. So for the example below, I have a grid with a date column. I want to feed in a string like ‘Within 1 week’ and then use that to filter for dates within 1 week. Thank you for any help.
import { AgGridAngular } from 'ag-grid-angular';
import { GridApi } from 'ag-grid-community';
@Component({
selector: 'app-grid',
template: `
<button (click)="filter()">Filter</button>
<ag-grid-angular
style="width: 500px; height: 200px;"
class="ag-theme-alpine"
[rowData]="rowData"
[columnDefs]="columnDefs"
(gridReady)="onGridReady($event)">
</ag-grid-angular>
`,
})
export class GridComponent {
columnDefs = [
{ headerName: 'Name', field: 'name' },
{ headerName: 'Date', field: 'date', filter: 'agSetColumnFilter' }
];
rowData = [
{ name: 'John Doe', date: '05-01-2024' },
{ name: 'Jane Smith', age: '04-01-2023' },
{ name: 'Bob Johnson', age: '04-02-2023' }
];
gridApi: GridApi;
onGridReady(params): void {
this.gridApi = params.api;
}
filter() {
const model = [];
mode['date'] = {type: 'set', values: ['Within 1 week']};
this.gridApi.setFilterModel(model);
}
}