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
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ function _createFacetedRowModel<
columnId: string,
preRowModel: RowModel<TFeatures, TData>,
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
}

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TFeatures, TData> & Partial<Row_ColumnFiltering<TFeatures, TData>>
>
Expand Down Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof features, TestRow>({
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', () => {
Expand Down
Loading