diff --git a/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts b/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts index 4ad66d25be..a2b55d3dc3 100644 --- a/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts +++ b/packages/table-core/src/features/column-faceting/createFacetedRowModel.ts @@ -54,9 +54,15 @@ function _createFacetedRowModel< columnId: string, preRowModel: RowModel, columnFilters?: ColumnFiltersState, - globalFilter?: string, + globalFilter?: any, ) { - if (!preRowModel.rows.length || (!columnFilters?.length && !globalFilter)) { + const hasGlobalFilter = + globalFilter !== undefined && globalFilter !== null && globalFilter !== '' + + if ( + !preRowModel.rows.length || + (!columnFilters?.length && !hasGlobalFilter) + ) { return preRowModel } @@ -69,7 +75,7 @@ function _createFacetedRowModel< } // The global context excludes the global filter itself, mirroring how a // column's faceted model excludes that column's own filter - if (globalFilter && columnId !== '__global__') + if (hasGlobalFilter && columnId !== '__global__') filterableIds.push('__global__') if (!filterableIds.length) { diff --git a/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts b/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts index 505b0de17a..79ed4e1bc2 100644 --- a/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts +++ b/packages/table-core/src/features/column-filtering/createFilteredRowModel.ts @@ -57,8 +57,10 @@ function _createFilteredRowModel< const rowModel = table.getPreFilteredRowModel() const columnFilters = table.atoms.columnFilters?.get() const globalFilter = table.atoms.globalFilter?.get() + const hasGlobalFilter = + globalFilter !== undefined && globalFilter !== null && globalFilter !== '' - if (!rowModel.rows.length || (!columnFilters?.length && !globalFilter)) { + if (!rowModel.rows.length || (!columnFilters?.length && !hasGlobalFilter)) { const flatRows = rowModel.flatRows as Array< Row & Partial> > @@ -106,7 +108,7 @@ function _createFilteredRowModel< .getAllLeafColumns() .filter((column) => column_getCanGlobalFilter(column)) - if (globalFilter && globalFilterFn && globallyFilterableColumns.length) { + if (hasGlobalFilter && globalFilterFn && globallyFilterableColumns.length) { filterableIds.push('__global__') globallyFilterableColumns.forEach((column) => { diff --git a/packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts b/packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts index 1722c7934c..455a34f509 100644 --- a/packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts +++ b/packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts @@ -509,6 +509,19 @@ describe('createFilteredRowModel', () => { expect(rowNames(table.getFilteredRowModel().rows)).toEqual(['Keep Me']) }) + + it('should apply a numeric zero global filter value', () => { + const table = constructTable({ + features, + columns, + data: [{ name: 'status 0' }, { name: 'status 1' }], + initialState: { + globalFilter: 0, + }, + }) + + expect(rowNames(table.getFilteredRowModel().rows)).toEqual(['status 0']) + }) }) describe('unresolvable global filter fn', () => {