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

Commit 311b3b5

Browse files
authored
Merge pull request #303 from Hypercubed/feature/external-sorting
External sorting option
2 parents 9e6e456 + 5ecbe00 commit 311b3b5

3 files changed

Lines changed: 26 additions & 19 deletions

File tree

demos/paging.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@
7373
columnMode: 'force',
7474
paging: {
7575
externalPaging: true,
76-
size: 10,
77-
countText: (count) => `${count} records`
76+
size: 10
77+
},
78+
onSort: (sorts) => {
79+
console.log({ sorts });
7880
}
7981
};
8082

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
@@ -73,7 +73,10 @@ export const TableDefaults = {
7373
offsetY: 0,
7474
innerWidth: 0,
7575
bodyHeight: 300
76-
}
76+
},
77+
78+
// flag if sorting shuld be handeled externally
79+
externalSorting: false
7780
};
7881

7982
/**

0 commit comments

Comments
 (0)