Skip to content

Commit

Permalink
fixes #794 - sort reset after third click
Browse files Browse the repository at this point in the history
  • Loading branch information
xaksis committed Mar 2, 2021
1 parent afe09f3 commit 20068fc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
6 changes: 4 additions & 2 deletions dev/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default {
filterOptions: {
enabled: true,
placeholder: 'All',
trigger: 'enter',
// filterDropdownItems: ['Chris', 'Dan', 'Susan'],
// filterValue: 'Chris',
},
Expand All @@ -80,8 +81,9 @@ export default {
firstSortType: 'desc',
filterOptions: {
enabled: true,
filterDropdownItems: ['24', '16', '30'],
styleClass: 'class1'
// filterDropdownItems: ['24', '16', '30'],
styleClass: 'class1',
trigger: 'enter',
// filterDropdownItems: [
// {
// value: 24,
Expand Down
45 changes: 28 additions & 17 deletions src/components/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@
</template>

<script>
import {
DEFAULT_SORT_TYPE,
SORT_TYPES,
} from './utils/constants';
import isEqual from 'lodash.isequal';
import defaultType from './types/default';
import VgtPagination from './pagination/VgtPagination.vue';
Expand Down Expand Up @@ -824,23 +828,30 @@ export default {
//* we need to get column for each sort
let sortValue;
for (let i = 0; i < this.sorts.length; i += 1) {
const column = this.getColumnForField(this.sorts[i].field);
const xvalue = this.collect(xRow, this.sorts[i].field);
const yvalue = this.collect(yRow, this.sorts[i].field);
//* if a custom sort function has been provided we use that
const { sortFn } = column;
if (sortFn && typeof sortFn === 'function') {
sortValue =
sortValue ||
sortFn(xvalue, yvalue, column, xRow, yRow) *
(this.sorts[i].type === 'desc' ? -1 : 1);
} else {
//* else we use our own sort
sortValue =
sortValue ||
column.typeDef.compare(xvalue, yvalue, column) *
(this.sorts[i].type === 'desc' ? -1 : 1);
const srt = this.sorts[i];
if (srt.type === SORT_TYPES.None) {
//* if no sort, we need to use the original index to sort.
sortValue = sortValue || (xRow.originalIndex - yRow.originalIndex);
} else{
const column = this.getColumnForField(srt.field);
const xvalue = this.collect(xRow, srt.field);
const yvalue = this.collect(yRow, srt.field);
//* if a custom sort function has been provided we use that
const { sortFn } = column;
if (sortFn && typeof sortFn === 'function') {
sortValue =
sortValue ||
sortFn(xvalue, yvalue, column, xRow, yRow) *
(srt.type === SORT_TYPES.Descending ? -1 : 1);
} else {
//* else we use our own sort
sortValue =
sortValue ||
column.typeDef.compare(xvalue, yvalue, column) *
(srt.type === SORT_TYPES.Descending ? -1 : 1);
}
}
}
return sortValue;
Expand Down
2 changes: 2 additions & 0 deletions src/components/utils/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ function getCurrentPrimarySort(sortArray, column) {
function getNextSort(currentSort) {
if (currentSort === SORT_TYPES.Ascending) {
return SORT_TYPES.Descending;
} else if (currentSort === SORT_TYPES.Descending) {
return SORT_TYPES.None;
}
return SORT_TYPES.Ascending;
}
Expand Down

0 comments on commit 20068fc

Please sign in to comment.