Skip to content
This repository has been archived by the owner on Dec 4, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
External sorting option
  • Loading branch information
Hypercubed committed Nov 30, 2019
1 parent ffd902c commit 27df725
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
3 changes: 3 additions & 0 deletions demos/paging.html
Expand Up @@ -74,6 +74,9 @@
paging: {
externalPaging: true,
size: 10
},
onSort: (sorts) => {
console.log({ sorts });
}
};

Expand Down
34 changes: 18 additions & 16 deletions src/components/DataTableController.js
Expand Up @@ -167,25 +167,27 @@ export class DataTableController {
this.options.onSort(sorts);
}

var clientSorts = [];
for(var i=0, len=sorts.length; i < len; i++) {
var c = sorts[i];
if(c.comparator !== false){
var dir = c.sort === 'asc' ? '' : '-';
if (c.sortBy !== undefined) {
clientSorts.push(dir + c.sortBy);
} else {
clientSorts.push(dir + c.prop);
if (!this.options.externalSorting) {
var clientSorts = [];
for(var i=0, len=sorts.length; i < len; i++) {
var c = sorts[i];
if(c.comparator !== false){
var dir = c.sort === 'asc' ? '' : '-';
if (c.sortBy !== undefined) {
clientSorts.push(dir + c.sortBy);
} else {
clientSorts.push(dir + c.prop);
}
}
}
}

if(clientSorts.length){
// todo: more ideal to just resort vs splice and repush
// but wasn't responding to this change ...
var sortedValues = this.$filter('orderBy')(this.rows, clientSorts);
this.rows.splice(0, this.rows.length);
this.rows.push(...sortedValues);
if(clientSorts.length){
// todo: more ideal to just resort vs splice and repush
// but wasn't responding to this change ...
var sortedValues = this.$filter('orderBy')(this.rows, clientSorts);
this.rows.splice(0, this.rows.length);
this.rows.push(...sortedValues);
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/defaults.js
Expand Up @@ -68,7 +68,10 @@ export const TableDefaults = {
offsetY: 0,
innerWidth: 0,
bodyHeight: 300
}
},

// flag if sorting shuld be handeled externally
externalSorting: false

};

Expand Down

0 comments on commit 27df725

Please sign in to comment.