Skip to content

Commit 8e5d805

Browse files
authored
🤖 Merge PR DefinitelyTyped#73455 Additional definitions for Filters by @ljulien
1 parent 236e35c commit 8e5d805

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

types/tabulator-tables/index.d.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ export interface ColumnDefinition extends ColumnLayout, CellCallbacks {
14081408
*/
14091409
headerFilterFunc?:
14101410
| FilterType
1411-
| ((headerValue: any, rowValue: any, rowData: any, filterParams: any) => boolean)
1411+
| HeaderFilterFunc
14121412
| undefined;
14131413

14141414
/** additional parameters object passed to the headerFilterFunc function. */
@@ -3069,7 +3069,7 @@ declare class Tabulator {
30693069
addFilter: FilterFunction;
30703070

30713071
/** You can retrieve an array of the current programmatic filters using the getFilters function, this will not include any of the header filters: */
3072-
getFilters: (includeHeaderFilters: boolean) => Filter[];
3072+
getFilters: (includeHeaderFilters?: boolean) => Filter[];
30733073

30743074
/** You can programmatically set the header filter value of a column by calling the setHeaderFilterValue function, This function takes any of the standard column component look up options as its first parameter, with the value for the header filter as the second option. */
30753075
setHeaderFilterValue: (column: ColumnLookup, value: string) => void;
@@ -3424,6 +3424,11 @@ declare class Module {
34243424
*/
34253425
initialize(): void;
34263426
}
3427+
3428+
export interface HeaderFilterFunc {
3429+
(headerValue: any, rowValue: any, rowData: any, filterParams: any): boolean;
3430+
}
3431+
34273432
declare class AccessorModule extends Module {}
34283433
declare class AjaxModule extends Module {}
34293434
declare class ClipboardModule extends Module {}
@@ -3432,7 +3437,14 @@ declare class DataTreeModule extends Module {}
34323437
declare class DownloadModule extends Module {}
34333438
declare class EditModule extends Module {}
34343439
declare class ExportModule extends Module {}
3435-
declare class FilterModule extends Module {}
3440+
declare class FilterModule extends Module {
3441+
/**
3442+
* Default filter functions (i.e. '=', '<', 'regex', etc.)
3443+
*/
3444+
static filters: {
3445+
[key: string]: HeaderFilterFunc;
3446+
};
3447+
}
34363448
declare class FormatModule extends Module {}
34373449
declare class FrozenColumnsModule extends Module {}
34383450
declare class FrozenRowsModule extends Module {}

types/tabulator-tables/tabulator-tables-tests.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ColumnDefinition,
88
ColumnDefinitionSorterParams,
99
DataTreeModule,
10+
FilterModule,
1011
GroupComponent,
1112
InputParams,
1213
JSONRecord,
@@ -399,6 +400,10 @@ colDef.headerFilterFunc = (headerValue, rowValue, rowData, filterParams) => {
399400
return rowData.name === filterParams.name && rowValue < headerValue; // must return a boolean, true if it passes the filter.
400401
};
401402

403+
colDef.headerFilterFuncParams = {
404+
myParam: "my param",
405+
};
406+
402407
// Calculation
403408
colDef.bottomCalc = (values, data, calcParams) => {
404409
return {};
@@ -1838,3 +1843,12 @@ table = new Tabulator("#test-selectableRowsCheck", {
18381843
{ title: "Name", field: "name", headerMenu: headerMenuFunc },
18391844
],
18401845
});
1846+
1847+
// Testing FilterModule
1848+
// getFilters can take a boolean or no arguments (it defaults to false)
1849+
table.setFilter("name", "<=", 3);
1850+
table.getFilters();
1851+
table.getFilters(true);
1852+
table.getFilters(false);
1853+
// $ExpectType HeaderFilterFunc
1854+
FilterModule.filters[0];

0 commit comments

Comments
 (0)