Skip to content

Commit

Permalink
finetune sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
xaksis committed Oct 29, 2018
1 parent 198e260 commit 4396893
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion dev/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
:columns="columns"
:rows="rows"
theme="black-rhino"
:fixed-header="true"
max-height="200px"
:pagination-options="{
mode: 'pages',
perPage: 3,
Expand All @@ -35,7 +37,6 @@
:search-options="{
enabled: true,
skipDiacritics: true,
trigger: 'enter',
}">
</vue-good-table>
<h3>Grouped Table</h3>
Expand Down
11 changes: 7 additions & 4 deletions src/components/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,10 @@ export default {
},
sortOptions: {
handler() {
this.initializeSort();
handler(newValue, oldValue) {
if (!isEqual(newValue, oldValue)) {
this.initializeSort();
}
},
deep: true,
},
Expand Down Expand Up @@ -1322,11 +1324,12 @@ export default {
//* initialSortBy can be an array or an object
if (typeof initialSortBy === 'object') {
const ref = this.fixedHeader ? this.$refs['table-header-secondary'] : this.$refs['table-header-primary'];
if (Array.isArray(initialSortBy)) {
this.$refs['table-header-primary'].setInitialSort(initialSortBy);
ref.setInitialSort(initialSortBy);
} else {
const hasField = Object.prototype.hasOwnProperty.call(initialSortBy, 'field');
if (hasField) this.$refs['table-header-primary'].setInitialSort([initialSortBy]);
if (hasField) ref.setInitialSort([initialSortBy]);
}
}
},
Expand Down
4 changes: 3 additions & 1 deletion src/components/VgtTableHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ export default {
getColumnSort(column) {
for (let i = 0; i < this.sorts.length; i += 1) {
if (this.sorts[i].field === column.field) return this.sorts[i].type;
if (this.sorts[i].field === column.field) {
return this.sorts[i].type || 'asc';
}
}
return null;
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/utils/sort.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

function getNextSort(currentSort) {
if (currentSort === 'asc') return 'desc';
if (currentSort === 'desc') return null;
// if (currentSort === 'desc') return null;
return 'asc';
}

Expand Down

0 comments on commit 4396893

Please sign in to comment.