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 @@ -35,10 +35,12 @@ export const globalFilteringFeature: TableFeature = {
return true
}

const value = table
const row = table
.getCoreRowModel()
.flatRows[0]?.getAllCellsByColumnId()
[column.id]?.getValue()
.flatRows.find(
(row) => row.getAllCellsByColumnId()[column.id]?.getValue() != null,
)
const value = row?.getAllCellsByColumnId()[column.id]?.getValue()

return typeof value === 'string' || typeof value === 'number'
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,26 @@ describe('createFilteredRowModel', () => {
})

describe('global filtering edge cases', () => {
it('should filter a column when its first row value is undefined', () => {
type NullableNameRow = { name?: string }
const nullableColumns: Array<
ColumnDef<typeof features, NullableNameRow, any>
> = [{ accessorKey: 'name', id: 'name' }]

const table = constructTable<typeof features, NullableNameRow>({
features,
columns: nullableColumns,
data: [{ name: undefined }, { name: 'hello' }, { name: 'world' }],
initialState: {
globalFilter: 'hello',
},
})

expect(
table.getFilteredRowModel().rows.map((row) => row.original.name),
).toEqual(['hello'])
})

it('should globally filter an object-valued column that explicitly opts in', () => {
interface ObjectValueRow {
value: { label: string }
Expand Down
Loading