Alk
Alk

Reputation: 688

react-bootstrap-table2 sortFunc never called

I'm trying to customize the sort algorithm of a column. I saw in the documentation that I should use "sortFunc" to do so : Unfortunately I can't find the way to enter the function ever.

Here is my code :

const columns = [
  {
    align: "center",
    classes: "font_orange",
    dataField: "min",
    formatter: priceFormatter,
    sort: true,
    sortFunc: (a, b, order, dataField, rowA, rowB) => {
      let fA = parseFloat(a);
      let fB = parseFloat(b);
      console.log('IN');
      if (order === 'asc') {
        return fB - fA;
      }
      return fA - fB; // desc
    },
    style: { whiteSpace: "normal" },
    text: "Min price"
  },

The result is a column sorted as a string (like the default sorting algorithm) and no log 'IN' appearing in the console.

Upvotes: 0

Views: 1064

Answers (1)

Kimamisa
Kimamisa

Reputation: 81

If you have remote enabled:

All the changes are go though onTableChange listener, it's only way that table give fully control to you

https://react-bootstrap-table.github.io/react-bootstrap-table2/docs/basic-remote.html

that might be the reason why your hook is not called.

Upvotes: 1

Related Questions