Skip to content

Commit

Permalink
Merge pull request #191 from ashleahhill/add-deep-sort
Browse files Browse the repository at this point in the history
Add deep value getter to sortRows function
  • Loading branch information
amcdnl authored Oct 11, 2016
2 parents d348eff + e29e03c commit b20014c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utils/sort.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Sort } from '../models';
import { SortType, SortDirection } from '../types';

import { deepValueGetter } from './deep-getter';
/**
* Gets the next sort direction
* @param {SortType} sortType
Expand Down Expand Up @@ -64,9 +64,12 @@ export function sortRows(rows: Array<any>, dirs: Array<Sort>) {

return temp.sort(function(a: any, b: any) {
for(const { prop, dir } of dirs) {
let propA = deepValueGetter(a, prop);
let propB = deepValueGetter(b, prop);

const comparison = dir !== SortDirection.desc ?
orderByComparator(a[prop], b[prop]) :
-orderByComparator(a[prop], b[prop]);
orderByComparator(propA, propB) :
-orderByComparator(propA, propB);

// Don't return 0 yet in case of needing to sort by next property
if (comparison !== 0) return comparison;
Expand Down

0 comments on commit b20014c

Please sign in to comment.