Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions types/tabulator-tables/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1408,7 +1408,7 @@ export interface ColumnDefinition extends ColumnLayout, CellCallbacks {
*/
headerFilterFunc?:
| FilterType
| ((headerValue: any, rowValue: any, rowData: any, filterParams: any) => boolean)
| HeaderFilterFunc
| undefined;

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

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

/** 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. */
setHeaderFilterValue: (column: ColumnLookup, value: string) => void;
Expand Down Expand Up @@ -3424,6 +3424,11 @@ declare class Module {
*/
initialize(): void;
}

export interface HeaderFilterFunc {
(headerValue: any, rowValue: any, rowData: any, filterParams: any): boolean;
}

declare class AccessorModule extends Module {}
declare class AjaxModule extends Module {}
declare class ClipboardModule extends Module {}
Expand All @@ -3432,7 +3437,14 @@ declare class DataTreeModule extends Module {}
declare class DownloadModule extends Module {}
declare class EditModule extends Module {}
declare class ExportModule extends Module {}
declare class FilterModule extends Module {}
declare class FilterModule extends Module {
/**
* Default filter functions (i.e. '=', '<', 'regex', etc.)
*/
static filters: {
[key: string]: HeaderFilterFunc;
};
}
declare class FormatModule extends Module {}
declare class FrozenColumnsModule extends Module {}
declare class FrozenRowsModule extends Module {}
Expand Down
14 changes: 14 additions & 0 deletions types/tabulator-tables/tabulator-tables-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ColumnDefinition,
ColumnDefinitionSorterParams,
DataTreeModule,
FilterModule,
GroupComponent,
InputParams,
JSONRecord,
Expand Down Expand Up @@ -399,6 +400,10 @@ colDef.headerFilterFunc = (headerValue, rowValue, rowData, filterParams) => {
return rowData.name === filterParams.name && rowValue < headerValue; // must return a boolean, true if it passes the filter.
};

colDef.headerFilterFuncParams = {
myParam: "my param",
};

// Calculation
colDef.bottomCalc = (values, data, calcParams) => {
return {};
Expand Down Expand Up @@ -1838,3 +1843,12 @@ table = new Tabulator("#test-selectableRowsCheck", {
{ title: "Name", field: "name", headerMenu: headerMenuFunc },
],
});

// Testing FilterModule
// getFilters can take a boolean or no arguments (it defaults to false)
table.setFilter("name", "<=", 3);
table.getFilters();
table.getFilters(true);
table.getFilters(false);
// $ExpectType HeaderFilterFunc
FilterModule.filters[0];