-
Notifications
You must be signed in to change notification settings - Fork 0
/
agGridFilterUtils.ts
65 lines (59 loc) · 1.98 KB
/
agGridFilterUtils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { GridApi, ISetFilter, NumberFilter, TextFilter } from 'ag-grid-community';
import { ISimpleFilterModelType } from 'ag-grid-community/dist/lib/filter/provided/simpleFilter';
import { SetFilterModelValue } from 'ag-grid-community/dist/lib/interfaces/iSetFilter';
export function setTextFilter(api: GridApi, field: string, value: string | null) {
const filterInstance = api.getFilterInstance(field) as TextFilter;
if (filterInstance) {
let type: ISimpleFilterModelType | null | undefined;
let filterValue = null;
if (value) {
let split = value.split(':');
type = split[0] as ISimpleFilterModelType;
filterValue = split[1];
}
if (filterValue && type) {
filterInstance.setModel({
filter: filterValue,
type: type,
});
filterInstance.applyModel();
}
}
}
export function setNumberFilter(api: GridApi, field: string, value: string | null) {
const filterInstance = api.getFilterInstance(field) as NumberFilter;
if (filterInstance) {
let type: ISimpleFilterModelType | null | undefined;
let filterValue = null;
if (value) {
let split = value.split(':');
type = split[0] as ISimpleFilterModelType;
filterValue = split[1];
}
if (filterValue && type) {
filterInstance.setModel({
filter: Number(filterValue),
type: type,
});
filterInstance.applyModel();
}
}
}
export function setSetFilter(api: GridApi, field: string, value: string | null) {
const filterInstance = api.getFilterInstance(field) as ISetFilter;
if (filterInstance) {
let filterValues: SetFilterModelValue = [];
if (value) {
filterValues = value.split(',');
}
if (filterValues.length > 0) {
if (filterInstance.getValues().length === 0) {
// this filter's values are fetched via server-side
// for now, enter the provided filters as values, they will be fully populated later when the server-side request returns
filterInstance.setFilterValues(filterValues);
}
filterInstance.setModel({ values: filterValues });
filterInstance.applyModel();
}
}
}