Error with number filtering
See original GitHub issueHi. I have found possible bug when trying to filter an array with number type fields containing the same values
match-sorter
version: 3.5.1node
version: 10.15.3npm
version: 6.9.0
Code Example:
let p = [{ name: 'samuel', likes: 0 }, { name: 'pedro', likes: 0 }];
const result = matchSorter(p, '0', {
keys: ['name', 'likes'],
threshold: rankings.WORD_STARTS_WITH
});
console.log(result);
Error:
TypeError aRankedItem.localeCompare is not a function
Problem: If I’m not mistaken, the problem is that the match-sorter try to call the function <localeCompare> of the String class from a variable of Number type. My solution was simply, when trying to compare, I cast the variable to String in any case.
Possible Solution:
function sortRankedItems(a, b) {
var aFirst = -1;
var bFirst = 1;
var aRankedItem = a.rankedItem,
aRank = a.rank,
aKeyIndex = a.keyIndex;
var bRankedItem = b.rankedItem,
bRank = b.rank,
bKeyIndex = b.keyIndex;
if (aRank === bRank) {
if (aKeyIndex === bKeyIndex) {
return String(aRankedItem).localeCompare(bRankedItem);
} else {
return aKeyIndex < bKeyIndex ? aFirst : bFirst;
}
} else {
return aRank > bRank ? aFirst : bFirst;
}
}
I dont know if it’s good solution but works perfect for now.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Error (Filtering using a number on a column which
Filtering using a number on a column which contains both strings and numbers is not currently supported. Its a very simple flow.
Read more >Error when global filter called for numeric columns · Issue #4210
Using the latest ColumDefs documentation, I updated my numeric columns to display a string instead of a number (since it doesn't really make ......
Read more >How to use Excel filtering to resolve file format errors
Right-click (or Control-click on a Mac) on the cell containing the data in error. On Windows, select Filter > Filter by Selected Cell's...
Read more >ELMAH—Error Filtering Examples
To learn more about how to filter harmless or noisy errors from your logs, see “Error Filtering”. Filter requests for favicon.ico that end...
Read more >FIltering on blank number returns error - DNNSharp Helpcenter
When using the filter on a column containing only numbers (including blanks), filtering on a blank number returns an error (Cannot perform '='...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That suggested solution sounds great to me. Would you be willing to implement it?
Maybe this will help: https://kcd.im/pull-request