Skip to content

Commit a27ccc4

Browse files
authored
Merge pull request #152 from bindable-ui/djedi/hotfix/table-sort-but-fx
Fix table sorting bug with reverseSort
2 parents 9f5fdb4 + 4bb0256 commit a27ccc4

File tree

6 files changed

+38
-41
lines changed

6 files changed

+38
-41
lines changed

dev-app/app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<c-nav-horizontal-item
5353
position="right"
5454
href="https://github.com/bindable-ui/bindable"
55-
title="v1.11.8"
55+
title="v1.11.10"
5656
></c-nav-horizontal-item>
5757
</c-nav-horizontal>
5858
</l-box>

dev-app/routes/components/tables/table/properties/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,30 +155,41 @@ export class TableProperties {
155155
colHeadName: 'gender',
156156
colHeadValue: 'Gender',
157157
},
158+
{
159+
colClass: 't85',
160+
colHeadName: 'number',
161+
colHeadValue: 'revSort',
162+
sort: true,
163+
reverseSort: true,
164+
},
158165
];
159166

160167
this.sortableData = [
161168
{
162169
gender: 'Male',
163170
name: 'Luke Skywalker',
164171
ship: 'X-Wing',
172+
number: 4,
165173
},
166174
{
167175
_status: 'critical',
168176
gender: 'Male',
169177
name: 'Fin',
170178
ship: 'Tie Fighter',
179+
number: 2,
171180
},
172181
{
173182
gender: 'Male',
174183
name: 'Han Solo',
175184
ship: 'M. Falcon',
185+
number: 3,
176186
},
177187
{
178188
_status: 'healthy',
179189
gender: 'Female',
180190
name: 'Rey',
181191
ship: 'M. Falcon',
192+
number: 1,
182193
},
183194
];
184195
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@bindable-ui/bindable",
33
"description": "An Aurelia component library",
4-
"version": "1.11.9",
4+
"version": "1.11.10",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/bindable-ui/bindable"

src/components/tables/c-table/c-table.test.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ describe('c-table component', () => {
579579
expect(col.sortClass).toBe(component.styles.sortDesc);
580580
});
581581

582-
it('will sort desc when col reverseSort', () => {
582+
it('will sort asc still when col reverseSort', () => {
583583
const col: any = {
584584
_class: 'code',
585585
_status: 'warning',
@@ -594,25 +594,7 @@ describe('c-table component', () => {
594594

595595
component.setColSortClass(col);
596596

597-
expect(col.sortClass).toBe(component.styles.sortDesc);
598-
});
599-
600-
it('will sort desc when table reverseSort', () => {
601-
const col: any = {
602-
_class: 'code',
603-
_status: 'warning',
604-
colClass: 't150',
605-
colHeadName: 'name',
606-
colHeadValue: 'Name',
607-
sort: true,
608-
};
609-
610-
component.reverseSort = true;
611-
component.defaultSortCol = `${col.colHeadName}`;
612-
613-
component.setColSortClass(col);
614-
615-
expect(col.sortClass).toBe(component.styles.sortDesc);
597+
expect(col.sortClass).toBe(component.styles.sortAsc);
616598
});
617599
});
618600

src/components/tables/c-table/c-table.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,18 @@ export class CTable {
190190
}
191191

192192
let sortClass = this.styles.sortNone;
193-
const isReverse = /^-/.test(this.defaultSortCol);
193+
const isDescending = /^-/.test(this.defaultSortCol);
194194
const defaultSortCol = this.defaultSortCol.replace(/^-/, '');
195195

196+
// I think the classes are backwards
197+
const asc = this.styles.sortAsc;
198+
const desc = this.styles.sortDesc;
199+
196200
if (col.colHeadName === defaultSortCol) {
201+
const reversedColumn: boolean = Boolean(col.reverseSort);
197202
const {reverseSort = false} = col;
198203

199-
if (isReverse) {
200-
sortClass = this.styles.sortDesc;
201-
} else if (reverseSort) {
202-
sortClass = col.reverseSort ? this.styles.sortDesc : this.styles.sortAsc;
203-
} else {
204-
sortClass = this.reverseSort ? this.styles.sortDesc : this.styles.sortAsc;
205-
}
204+
sortClass = isDescending ? desc : asc;
206205
}
207206

208207
col.sortClass = sortClass;
@@ -217,21 +216,26 @@ export class CTable {
217216
});
218217

219218
let reverse: boolean;
219+
const reversedColumn: boolean = Boolean(col.reverseSort);
220+
221+
const asc = this.styles.sortAsc;
222+
const desc = this.styles.sortDesc;
223+
220224
// Use reverseSort property of column or reverse-sort binding of table (in that order)
221225
// to determine initial sort. After initial sort, just toggle.
222226
if (col.sortClass === this.styles.sortNone) {
223-
if (typeof col.reverseSort === 'boolean') {
224-
col.sortClass = col.reverseSort ? this.styles.sortDesc : this.styles.sortAsc;
225-
reverse = col.reverseSort;
227+
if (reversedColumn) {
228+
col.sortClass = desc;
229+
reverse = true;
226230
} else {
227-
col.sortClass = this.reverseSort ? this.styles.sortDesc : this.styles.sortAsc;
228-
reverse = this.reverseSort;
231+
col.sortClass = asc;
232+
reverse = false;
229233
}
230-
} else if (col.sortClass === this.styles.sortAsc) {
231-
col.sortClass = this.styles.sortDesc;
234+
} else if (col.sortClass === asc) {
235+
col.sortClass = desc;
232236
reverse = true;
233237
} else {
234-
col.sortClass = this.styles.sortAsc;
238+
col.sortClass = asc;
235239
reverse = false;
236240
}
237241
if (this.actions && this.actions.sortColumn) {

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2217,9 +2217,9 @@ caniuse-api@^3.0.0:
22172217
lodash.uniq "^4.5.0"
22182218

22192219
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001317:
2220-
version "1.0.30001328"
2221-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001328.tgz#0ed7a2ca65ec45872c613630201644237ba1e329"
2222-
integrity sha512-Ue55jHkR/s4r00FLNiX+hGMMuwml/QGqqzVeMQ5thUewznU2EdULFvI3JR7JJid6OrjJNfFvHY2G2dIjmRaDDQ==
2220+
version "1.0.30001436"
2221+
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001436.tgz"
2222+
integrity sha512-ZmWkKsnC2ifEPoWUvSAIGyOYwT+keAaaWPHiQ9DfMqS1t6tfuyFYoWR78TeZtznkEQ64+vGXH9cZrElwR2Mrxg==
22232223

22242224
capture-exit@^2.0.0:
22252225
version "2.0.0"

0 commit comments

Comments
 (0)