Using react-bootstrap-table2, When trying to filter large numbers with commas (12,000) it doesn't work. Is it possible to filter numbers with commas?
Cheers!
Using react-bootstrap-table2, When trying to filter large numbers with commas (12,000) it doesn't work. Is it possible to filter numbers with commas?
Cheers!
Without seeing your code it is hard to say. But perhaps each cell data in your table is a string, not a number, which could cause sorting weirdness. I had same issue before. Sort it by number, then populate your table cells with the formatted string version of the number after sort, if that makes sense.
Let's assume that:
You can write your sort function (sortFunc
) as follows:
{
dataField: 'estimation',
text: 'Estimation',
sort: true,
sortFunc: (a, b, order, dataField, rowA, rowB) => {
const numA = parseFloat(a.replace('\'', '').replace(',', '.'));
const numB = parseFloat(b.replace('\'', '').replace(',', '.'));
if (order === "asc") {
return numB - numA;
}
return numA - numB;
}
I solved this problem, here is my Bootstrap Table sort function。
sortFunc: (a, b, order) => {
const numA = parseFloat(a.replace(/\,/g,''), 10)
const numB = parseFloat(b.replace(/\,/g,''), 10)
if (order === "asc") {
return numB - numA;
}
return numA - numB;
}
import ToolkitProvider, { Search } from "react-bootstrap-table2-toolkit";
import paginationFactory from "react-bootstrap-table2-paginator";
First please check number or non-number.
If your array inside number return number else is non-number :
yourDataArray.map(function (item, x) {
item._Number_of_stocks = parseInt(item.Number_of_stocks);
});
Sort function in here:
sortFunc: (a, b, order, dataField, rowA, rowB) => {
if (order === "asc") {
return (
isNaN(rowB._Number_of_stocks) - !isNaN(rowB._Number_of_stocks)
);
}
return !isNaN(rowB._Number_of_stocks) - isNaN(rowB._Number_of_stocks);
},
See: https://github.com/react-bootstrap-table/react-bootstrap-table2/blob/master/docs/columns.md