Merge pull request #508 from react-bootstrap-table/enhance/501

fix #501
This commit is contained in:
Allen 2018-08-26 13:25:59 +08:00 committed by GitHub
commit d64ee2e5e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -121,15 +121,15 @@ It's only used for [`column.formatter`](#formatter), you can define any value fo
Enable the column sort via a `true` value given.
## <a name='sortFunc'>column.sortFunc - [Function]</a>
`column.sortFunc` only work when `column.sort` is enable. `sortFunc` allow you to define your sorting algorithm. This callback function accept four arguments:
`column.sortFunc` only work when `column.sort` is enable. `sortFunc` allow you to define your sorting algorithm. This callback function accept six arguments:
```js
{
// omit...
sort: true,
sortFunc: (a, b, order, dataField) => {
if (order === 'asc') return a - b;
else return b - a;
sortFunc: (valueA, valueB, order, dataField, rowA, rowB) => {
if (order === 'asc') return valueA - valueB;
else return valueB - valueA;
}
}
```

View File

@ -24,7 +24,7 @@ export const sort = (data, sortOrder, { dataField, sortFunc }) => {
valueB = _.isDefined(valueB) ? valueB : '';
if (sortFunc) {
result = sortFunc(valueA, valueB, sortOrder, dataField);
result = sortFunc(valueA, valueB, sortOrder, dataField, a, b);
} else {
if (sortOrder === Const.SORT_DESC) {
result = comparator(valueA, valueB);