Skip to content

Commit 8df2d0b

Browse files
authored
fix: Date sort support + avoid null sorts comparison (#3243)
1 parent 6be6610 commit 8df2d0b

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

app/components/tables/headers/sort.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import Component from '@ember/component';
22
import { computed } from '@ember/object';
3+
import { kebabCase } from 'lodash-es';
34

45
export default class extends Component {
56
@computed('[email protected]', 'sortDir')
67
get sortIcon() {
78
if (this.sorts && this.sorts[0] && this.sorts[0].valuePath === this.column.valuePath) {
8-
this.set('sortDirection', this.sorts[0].isAscending ? 'ASC' : 'DES');
99
if (this.sorts[0].isAscending) {
10-
// support got sort up, sort down to come with next release of semantic-ui-ember
10+
// support for sort up, sort down to come with next release of semantic-ui-ember
1111
return 'caret up';
1212
} else {
1313
return 'caret down';
@@ -21,15 +21,18 @@ export default class extends Component {
2121
super.didInsertElement(...arguments);
2222
if (this.sorts && this.sorts[0] && this.sorts[0].valuePath === this.column.valuePath) {
2323
this.setProperties({
24-
sortBy : this.sorts[0].valuePath,
24+
sortBy : kebabCase(this.sorts[0].valuePath), // Ensures field names are server compatible with sort
2525
sortDir : this.sorts[0].isAscending ? 'ASC' : 'DSC'
2626
});
2727

2828
} else {
29-
this.setProperties({
30-
sortBy : null,
31-
sortDir : null
32-
});
29+
// avoid resetting the query params, when sorts is uninitialised
30+
if (this.sorts && !this.sorts[0]) {
31+
this.setProperties({
32+
sortBy : null,
33+
sortDir : null
34+
});
35+
}
3336
}
3437
}
3538
}

app/controllers/events/list.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default class extends Controller {
88
search = null;
99
sort_dir = null;
1010
sort_by = null;
11-
11+
sorts = [];
1212
@computed()
1313
get columns() {
1414
return [
@@ -29,9 +29,11 @@ export default class extends Controller {
2929
}
3030
},
3131
{
32-
name : 'Date',
33-
valuePath : 'startsAt',
34-
cellComponent : 'ui-table/cell/cell-event-date'
32+
name : 'Date',
33+
valuePath : 'startsAt',
34+
isSortable : true,
35+
headerComponent : 'tables/headers/sort',
36+
cellComponent : 'ui-table/cell/cell-event-date'
3537

3638
},
3739
{

0 commit comments

Comments
 (0)