Added natural sorting for documents and collections
This commit is contained in:
10
shared/utils/naturalSort.js
Normal file
10
shared/utils/naturalSort.js
Normal file
@ -0,0 +1,10 @@
|
||||
// @flow
|
||||
|
||||
import _ from 'lodash';
|
||||
import naturalSort from 'natural-sort';
|
||||
|
||||
export default (sortableArray: Object[], key: string) => {
|
||||
let keys = sortableArray.map(object => object[key]);
|
||||
keys.sort(naturalSort());
|
||||
return _.sortBy(sortableArray, object => keys.indexOf(object[key]));
|
||||
};
|
Reference in New Issue
Block a user