Skip to content

Commit e28de38

Browse files
committed
remove column type checking out of comparisoin function
1 parent 0db2dfd commit e28de38

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/core/transformExecutors.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -256,24 +256,36 @@ export class SortExecutor extends TransformExecutor {
256256
// displayed values to maintain their original types but
257257
// be sorted as if they were all strings.
258258
const stringifyIfNeeded = (value: any) => {
259-
if (typeof value != 'string' && columnDataType == 'string') {
259+
if (typeof value != 'string') {
260260
return String(value);
261261
}
262262
return value;
263263
};
264264

265-
if (this._options.desc) {
266-
sortFunc = (a: any, b: any): number => {
267-
return stringifyIfNeeded(a[field]) < stringifyIfNeeded(b[field])
268-
? 1
269-
: -1;
270-
};
265+
if (columnDataType == 'string') {
266+
if (this._options.desc) {
267+
sortFunc = (a: any, b: any): number => {
268+
return stringifyIfNeeded(a[field]) < stringifyIfNeeded(b[field])
269+
? 1
270+
: -1;
271+
};
272+
} else {
273+
sortFunc = (a: any, b: any): number => {
274+
return stringifyIfNeeded(a[field]) > stringifyIfNeeded(b[field])
275+
? 1
276+
: -1;
277+
};
278+
}
271279
} else {
272-
sortFunc = (a: any, b: any): number => {
273-
return stringifyIfNeeded(a[field]) > stringifyIfNeeded(b[field])
274-
? 1
275-
: -1;
276-
};
280+
if (this._options.desc) {
281+
sortFunc = (a: any, b: any): number => {
282+
return a[field] < b[field] ? 1 : -1;
283+
};
284+
} else {
285+
sortFunc = (a: any, b: any): number => {
286+
return a[field] > b[field] ? 1 : -1;
287+
};
288+
}
277289
}
278290

279291
const data = input.data.slice(0);

0 commit comments

Comments
 (0)