-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v8] Global filter gives TypeError: l.toLowerCase is not a function
when using number fields
#4280
Comments
Experiencing the same issue in v8.5.11. The following is shown in Console:
declare module "@tanstack/table-core" {
interface FilterFns {
testFilter: FilterFn<unknown>;
}
}
function testFalsey(val: any) {
return val === undefined || val === null || val === "";
} const [globalFilter, setGlobalFilter] = useState("");
const testFilter: FilterFn<any> = (
row,
columnId: string,
filterValue: unknown,
) => {
console.log(columnId, filterValue);
return true;
};
testFilter.resolveFilterValue = (val: any) => {
console.log("resolveFilterValue", val);
return `${val}`;
};
testFilter.autoRemove = (val: any) => {
console.log("resolveFilterValue", val);
return testFalsey(`${val}`);
};
const table = useReactTable({
data,
columns,
state: {
globalFilter,
},
filterFns: {
testFilter,
},
onGlobalFilterChange: setGlobalFilter,
// globalFilterFn: testFilter, <-- custom filter is only triggered as globalFilterFn
getCoreRowModel: getCoreRowModel(),
getFilteredRowModel: getFilteredRowModel(),
}); Things I've tried:
|
I am so novice on this. I copied the includesString built-in function and converted the value to string. And now use that as the globalFilterFn.
|
As a temporary fix I added
To my number column |
@decayedCell unfortunately that is not really a fix when having a global filter in the first place 😉 |
Not sure what you mean by this. I have ran into the same issue, I have 2 tables and both use global filter and a search component that sets the global filter. For the table that only has strings as fields there are no issues, but on the other one I ran into the same issue mentioned by you. So I disabled GlobalFilter for only that column that uses numbers and now I have no issues using my search component. Obviously the negative is that that number column is completely ignored now, but until a fix it makes the table not crash at least while still providing the global filter functionality for the other columns. |
Exactly what I meant, the column is completely ignored and that's not what I want |
@marceloverdijk You can keep the data types intact and just pass in sanitized tableData before you initialize the table like this:
It's not as pretty as just passing in |
@marceloverdijk while this doesn't solve whatever the underlying issue in the code is... you can follow one of the examples to implement a fuzzy filter that replaces the global and seems to work fine. |
I took a page from @LautaroRiveiro suggestion by overriding the
|
I think the reason why this is happening is because of the following commit: a5578ac The default behavior of
I also hit this problem from a different direction - I wanted to filter on string array type columns - which is possible to do if you have a flexible filter function that handles array types - but that column would never appear because I think there are three things that could happen going forward, assuming the goal is that global filters should be type-flexible in the default case.
I also noticed if you don't supply a |
The same issue. I use the latest version I am getting There are one number-type data column, two string-type data columns and a number of display columns in my Table definition. (There is no group header) If I remove the sole number-type data column, the table does not render at all having the same error. |
I get the same "o.toLowerCase is not a function" error when I have a number-type column, even on latest v8.5.27 released today. I solved it by simply adding .toString() on the number column's accessorFn. While the solution is quite simple, it was not easy to understand and I hope it'll be fixed soon, or at least have better error handling so developers will have a better idea of what to do in this situation. |
Experiencing the same issue. Solved it thanks to @oldo's suggestion.
|
@oldo's solution did the trick for me. But, I was just wondering if there's an actual difference when validating the type of value this way:
The thing is that the conditional in the solution gives:
|
works fine when I used "includesString"? |
When you define your columns and you are going to filter specific data from a column make sure to add the filterFn: (row, id, value) => {
return value.includes(row.getValue(id))
} |
Thats worked for me! Thanks |
Alternative way to think about it I was working with date and numeric columns The column's I noticed that the
Below is an example of one column definition
|
Shouldn't this be the other way round? At least for me, to filter a filterFn: (row, id, value: string) => {
const rowValue = row.getValue<string>(id).toString();
return rowValue.includes(value);
}, |
Describe the bug
With latest
8.5.11
version using the Global filter in combination withnumber
fields gives:Note this was already raised in #4210 but still happens with latest version unfortunately.
I think this was introduced somewhere in
8.3.x
line as I first encountered this while upgrading from8.2.x
to8.3.3
.A workaround like
seems to work for the filtering, but this would also impact the sorting I would assume. Sorting on a string value instead of the number value will have impact (1, 2, 10 vs 1, 10, 2).
Your minimal, reproducible example
.
Steps to reproduce
See above.
Expected behavior
Global filter to work with number fields out of the box.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
macOS, chrome
react-table version
v8.5.11
TypeScript version
4.7.4
Additional context
If reproducible example is needed let me know.
Terms & Code of Conduct
The text was updated successfully, but these errors were encountered: