react-bootstrap-table/react-bootstrap-table2

sortfunc isn't working

Closed this issue · 4 comments

It doesn't being called.

               sort={{
                    sortCaret: (order, column) => {
                        if (!order) return (<img src={defaultSort}/>);
                        else if (order === 'asc') return (<img src={ascSort}/>);
                        else if (order === 'desc') return (<img src={descSort}/>);
                        return null;
                    },
                    sortFunc: (field, order) => {
                        onSortChange(field, order);
// tried sortFunc: onSortChange, - no luck
                    },
                }}

online demo is work

sortFunc is for custom the sorting logic. you information isn't helpful to me to reproduce your issue, please follow the instruction when u open the issue.

@AllenFang I disagree. It probably work with classes, but not with functions.
Even
sortFunc: (column, order) => {if (order === 'asc') return alert("123")}
doesn't work

I confirm in react-bootstrap-table-next@4.0.3, onSort and sortFunc aren't working.
For example, in columns definition, something like that does not logged anything to console :

{
  dataField: 'id',
  text: 'Product ID',
  sort: true,
  sortFunc: (a, b, order, dataField, rowA, rowB) => {
    console.log('sortFunc');
    if (order === 'asc') {
      return b - a;
    }
    return a - b; // desc
  },
  onSort: (field, order) => {
    console.log('onSort');
  }
}

It used to work in react-bootstrap-table-next@3.3.3..

Did I miss something ?

Thanks for you help.

Having the same issue. Sortfunc seems to trigger on some datafields, but not others. I have no clue why.