Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1424 Sorting with Undefined Values. #1473

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
"test:watch": "jest --watch"
},
"dependencies": {
"fast-sort": "^3.4.1",
"preact": "^10.10.6"
},
"changelog": {
Expand Down
22 changes: 21 additions & 1 deletion src/pipeline/sort/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../processor';
import Row from '../../row';
import log from '../../util/log';
import { inPlaceSort, ISortByObjectSorter } from 'fast-sort';

interface NativeSortProps extends PipelineProcessorProps {
columns: {
Expand Down Expand Up @@ -67,7 +68,26 @@ class NativeSort extends PipelineProcessor<Tabular, NativeSortProps> {

protected _process(data: Tabular): Tabular {
const sortedRows = [...data.rows];
sortedRows.sort(this.compareWrapper.bind(this));
/* sortedRows.sort(this.compareWrapper.bind(this)); */
let sortBys: ISortByObjectSorter<Row>[] = [];
for (const column of this.props.columns) {
let sortBy: ISortByObjectSorter = {};
if (column.direction === -1) {
sortBy.desc = (r: Row): TCell => {
return r.cells[column.index].data;
};
}
else {
sortBy.asc = (r: Row): TCell => {
return r.cells[column.index].data;
};
}
if (typeof column.compare === 'function') {
sortBy.comparer = column.compare;
}
sortBys.push(sortBy);
}
inPlaceSort(sortedRows).by(sortBys);

const sorted = new Tabular(sortedRows);
// we have to set the tabular length manually
Expand Down