@@ -11,7 +11,12 @@ import type { TableFeatures } from '../../types/TableFeatures'
1111import type { RowModel } from '../../types/RowModel'
1212import type { Table } from '../../types/Table'
1313import type { Column } from '../../types/Column'
14- import type { ColumnFiltersState , FilterFn } from './ColumnFiltering.types'
14+ import type {
15+ ColumnDef_ColumnFiltering ,
16+ ColumnFiltersState ,
17+ FilterFn ,
18+ TableOptions_ColumnFiltering ,
19+ } from './ColumnFiltering.types'
1520
1621export function column_getAutoFilterFn <
1722 TFeatures extends TableFeatures ,
@@ -49,11 +54,18 @@ export function column_getFilterFn<
4954 TFeatures extends TableFeatures ,
5055 TData extends RowData ,
5156 TValue extends CellData = CellData ,
52- > ( column : Column < TFeatures , TData , TValue > , table : Table < TFeatures , TData > ) {
57+ > (
58+ column : Column < TFeatures , TData , TValue > & {
59+ columnDef : ColumnDef_ColumnFiltering < TFeatures , TData >
60+ } ,
61+ table : Table < TFeatures , TData > & {
62+ options : TableOptions_ColumnFiltering < TFeatures , TData >
63+ } ,
64+ ) {
5365 return isFunction ( column . columnDef . filterFn )
5466 ? column . columnDef . filterFn
5567 : column . columnDef . filterFn === 'auto'
56- ? column . getAutoFilterFn ( )
68+ ? column_getAutoFilterFn ( column , table )
5769 : table . options . filterFns ?. [ column . columnDef . filterFn as string ] ??
5870 filterFns [ column . columnDef . filterFn as BuiltInFilterFn ]
5971}
@@ -62,7 +74,14 @@ export function column_getCanFilter<
6274 TFeatures extends TableFeatures ,
6375 TData extends RowData ,
6476 TValue extends CellData = CellData ,
65- > ( column : Column < TFeatures , TData , TValue > , table : Table < TFeatures , TData > ) {
77+ > (
78+ column : Column < TFeatures , TData , TValue > & {
79+ columnDef : ColumnDef_ColumnFiltering < TFeatures , TData >
80+ } ,
81+ table : Table < TFeatures , TData > & {
82+ options : TableOptions_ColumnFiltering < TFeatures , TData >
83+ } ,
84+ ) {
6685 return (
6786 ( column . columnDef . enableColumnFilter ?? true ) &&
6887 ( table . options . enableColumnFilters ?? true ) &&
@@ -75,15 +94,29 @@ export function column_getIsFiltered<
7594 TFeatures extends TableFeatures ,
7695 TData extends RowData ,
7796 TValue extends CellData = CellData ,
78- > ( column : Column < TFeatures , TData , TValue > , table : Table < TFeatures , TData > ) {
97+ > (
98+ column : Column < TFeatures , TData , TValue > & {
99+ columnDef : ColumnDef_ColumnFiltering < TFeatures , TData >
100+ } ,
101+ table : Table < TFeatures , TData > & {
102+ options : TableOptions_ColumnFiltering < TFeatures , TData >
103+ } ,
104+ ) {
79105 return column_getFilterIndex ( column , table ) > - 1
80106}
81107
82108export function column_getFilterValue <
83109 TFeatures extends TableFeatures ,
84110 TData extends RowData ,
85111 TValue extends CellData = CellData ,
86- > ( column : Column < TFeatures , TData , TValue > , table : Table < TFeatures , TData > ) {
112+ > (
113+ column : Column < TFeatures , TData , TValue > & {
114+ columnDef : ColumnDef_ColumnFiltering < TFeatures , TData >
115+ } ,
116+ table : Table < TFeatures , TData > & {
117+ options : TableOptions_ColumnFiltering < TFeatures , TData >
118+ } ,
119+ ) {
87120 return _table_getState ( table ) . columnFilters ?. find ( ( d ) => d . id === column . id )
88121 ?. value
89122}
@@ -93,8 +126,12 @@ export function column_getFilterIndex<
93126 TData extends RowData ,
94127 TValue extends CellData = CellData ,
95128> (
96- column : Column < TFeatures , TData , TValue > ,
97- table : Table < TFeatures , TData > ,
129+ column : Column < TFeatures , TData , TValue > & {
130+ columnDef : ColumnDef_ColumnFiltering < TFeatures , TData >
131+ } ,
132+ table : Table < TFeatures , TData > & {
133+ options : TableOptions_ColumnFiltering < TFeatures , TData >
134+ } ,
98135) : number {
99136 return (
100137 _table_getState ( table ) . columnFilters ?. findIndex (
@@ -108,12 +145,16 @@ export function column_setFilterValue<
108145 TData extends RowData ,
109146 TValue extends CellData = CellData ,
110147> (
111- column : Column < TFeatures , TData , TValue > ,
112- table : Table < TFeatures , TData > ,
148+ column : Column < TFeatures , TData , TValue > & {
149+ columnDef : ColumnDef_ColumnFiltering < TFeatures , TData >
150+ } ,
151+ table : Table < TFeatures , TData > & {
152+ options : TableOptions_ColumnFiltering < TFeatures , TData >
153+ } ,
113154 value : any ,
114155) {
115156 table_setColumnFilters ( table , ( old ) => {
116- const filterFn = column . getFilterFn ( )
157+ const filterFn = column_getFilterFn ( column , table )
117158 const previousFilter = old . find ( ( d ) => d . id === column . id )
118159
119160 const newFilter = functionalUpdate (
@@ -147,17 +188,22 @@ export function column_setFilterValue<
147188export function table_setColumnFilters <
148189 TFeatures extends TableFeatures ,
149190 TData extends RowData ,
150- > ( table : Table < TFeatures , TData > , updater : Updater < ColumnFiltersState > ) {
191+ > (
192+ table : Table < TFeatures , TData > & {
193+ options : TableOptions_ColumnFiltering < TFeatures , TData >
194+ } ,
195+ updater : Updater < ColumnFiltersState > ,
196+ ) {
151197 const leafColumns = table . getAllLeafColumns ( )
152198
153199 const updateFn = ( old : ColumnFiltersState ) => {
154200 return functionalUpdate ( updater , old ) . filter ( ( filter ) => {
155201 const column = leafColumns . find ( ( d ) => d . id === filter . id )
156202
157203 if ( column ) {
158- const filterFn = column . getFilterFn ( )
204+ const filterFn = column_getFilterFn ( column , table )
159205
160- if ( shouldAutoRemoveFilter ( filterFn , filter . value , column ) ) {
206+ if ( shouldAutoRemoveFilter ( filterFn , filter . value , column as any ) ) {
161207 return false
162208 }
163209 }
@@ -172,7 +218,12 @@ export function table_setColumnFilters<
172218export function table_resetColumnFilters <
173219 TFeatures extends TableFeatures ,
174220 TData extends RowData ,
175- > ( table : Table < TFeatures , TData > , defaultState ?: boolean ) {
221+ > (
222+ table : Table < TFeatures , TData > & {
223+ options : TableOptions_ColumnFiltering < TFeatures , TData >
224+ } ,
225+ defaultState ?: boolean ,
226+ ) {
176227 table_setColumnFilters (
177228 table ,
178229 defaultState ? [ ] : table . initialState . columnFilters ?? [ ] ,
@@ -182,14 +233,22 @@ export function table_resetColumnFilters<
182233export function table_getPreFilteredRowModel <
183234 TFeatures extends TableFeatures ,
184235 TData extends RowData ,
185- > ( table : Table < TFeatures , TData > ) {
236+ > (
237+ table : Table < TFeatures , TData > & {
238+ options : TableOptions_ColumnFiltering < TFeatures , TData >
239+ } ,
240+ ) {
186241 return table_getCoreRowModel ( table )
187242}
188243
189244export function table_getFilteredRowModel <
190245 TFeatures extends TableFeatures ,
191246 TData extends RowData ,
192- > ( table : Table < TFeatures , TData > ) : RowModel < TFeatures , TData > {
247+ > (
248+ table : Table < TFeatures , TData > & {
249+ options : TableOptions_ColumnFiltering < TFeatures , TData >
250+ } ,
251+ ) : RowModel < TFeatures , TData > {
193252 if ( ! table . _rowModels . Filtered ) {
194253 table . _rowModels . Filtered = table . options . _rowModels ?. Filtered ?.( table )
195254 }
0 commit comments