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

Commit 27df725

Browse files
committed
External sorting option
1 parent ffd902c commit 27df725

3 files changed

Lines changed: 25 additions & 17 deletions

File tree

demos/paging.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@
7474
paging: {
7575
externalPaging: true,
7676
size: 10
77+
},
78+
onSort: (sorts) => {
79+
console.log({ sorts });
7780
}
7881
};
7982

src/components/DataTableController.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,25 +167,27 @@ export class DataTableController {
167167
this.options.onSort(sorts);
168168
}
169169

170-
var clientSorts = [];
171-
for(var i=0, len=sorts.length; i < len; i++) {
172-
var c = sorts[i];
173-
if(c.comparator !== false){
174-
var dir = c.sort === 'asc' ? '' : '-';
175-
if (c.sortBy !== undefined) {
176-
clientSorts.push(dir + c.sortBy);
177-
} else {
178-
clientSorts.push(dir + c.prop);
170+
if (!this.options.externalSorting) {
171+
var clientSorts = [];
172+
for(var i=0, len=sorts.length; i < len; i++) {
173+
var c = sorts[i];
174+
if(c.comparator !== false){
175+
var dir = c.sort === 'asc' ? '' : '-';
176+
if (c.sortBy !== undefined) {
177+
clientSorts.push(dir + c.sortBy);
178+
} else {
179+
clientSorts.push(dir + c.prop);
180+
}
179181
}
180182
}
181-
}
182183

183-
if(clientSorts.length){
184-
// todo: more ideal to just resort vs splice and repush
185-
// but wasn't responding to this change ...
186-
var sortedValues = this.$filter('orderBy')(this.rows, clientSorts);
187-
this.rows.splice(0, this.rows.length);
188-
this.rows.push(...sortedValues);
184+
if(clientSorts.length){
185+
// todo: more ideal to just resort vs splice and repush
186+
// but wasn't responding to this change ...
187+
var sortedValues = this.$filter('orderBy')(this.rows, clientSorts);
188+
this.rows.splice(0, this.rows.length);
189+
this.rows.push(...sortedValues);
190+
}
189191
}
190192
}
191193

src/defaults.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ export const TableDefaults = {
6868
offsetY: 0,
6969
innerWidth: 0,
7070
bodyHeight: 300
71-
}
71+
},
72+
73+
// flag if sorting shuld be handeled externally
74+
externalSorting: false
7275

7376
};
7477

0 commit comments

Comments
 (0)