Skip to content

Commit

Permalink
#235 for TreeTable
Browse files Browse the repository at this point in the history
  • Loading branch information
cagataycivici committed Apr 18, 2020
1 parent 8eb7a75 commit 45d62fd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/components/treetable/TreeTable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export declare class TreeTable extends Vue {
defaultSortOrder?: number;
multiSortMeta?: any[];
sortMode?: string;
removableSort?: string;
filters?: {
[s: string]: any;
};
Expand Down
61 changes: 38 additions & 23 deletions src/components/treetable/TreeTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ export default {
type: String,
default: 'single'
},
removableSort: {
type: Boolean,
default: false
},
filters: {
type: Object,
default: null
Expand Down Expand Up @@ -417,52 +421,63 @@ export default {
},
onColumnHeaderClick(event, column) {
if (column.sortable) {
this.resetPage();
const targetNode = event.target;
const columnField = column.sortField || column.field;
if (DomHandler.hasClass(targetNode, 'p-sortable-column') || DomHandler.hasClass(targetNode, 'p-column-title')
|| DomHandler.hasClass(targetNode, 'p-sortable-column-icon') || DomHandler.hasClass(targetNode.parentElement, 'p-sortable-column-icon')) {
DomHandler.clearSelection();
const columnField = column.field || column.sortField;
this.d_sortOrder = (this.d_sortField === columnField) ? this.d_sortOrder * -1 : this.defaultSortOrder;
this.d_sortField = columnField;
if (this.sortMode === 'single') {
if (this.d_sortField === columnField) {
if (this.removableSort && (this.d_sortOrder * -1 === this.defaultSortOrder)) {
this.d_sortOrder = null;
this.d_sortField = null;
}
else {
this.d_sortOrder = this.d_sortOrder * -1
}
}
else {
this.d_sortOrder = this.defaultSortOrder;
this.d_sortField = columnField;
}
if(this.sortMode === 'multiple') {
this.$emit('update:sortField', this.d_sortField);
this.$emit('update:sortOrder', this.d_sortOrder);
}
else if (this.sortMode === 'multiple') {
let metaKey = event.metaKey || event.ctrlKey;
if (!metaKey) {
this.d_multiSortMeta = [];
this.d_multiSortMeta = this.d_multiSortMeta.filter(meta => meta.field === columnField);
}
this.addSortMeta({field: this.d_sortField, order: this.d_sortOrder});
this.addMultiSortField(columnField);
this.$emit('update:multiSortMeta', this.d_multiSortMeta);
}
this.$emit('update:sortField', this.d_sortFied);
this.$emit('update:sortOrder', this.d_sortOrder);
this.$emit('update:multiSortMeta', this.d_multiSortMeta);
this.$emit('sort', {
originalEvent: event,
sortField: this.d_sortField,
sortOrder: this.d_sortOrder,
multiSortMeta: this.d_multiSortMeta
});
this.resetPage();
}
}
},
addSortMeta(meta) {
let index = -1;
for (let i = 0; i < this.d_multiSortMeta.length; i++) {
if (this.d_multiSortMeta[i].field === meta.field) {
index = i;
break;
}
}
addMultiSortField(field) {
let index = this.d_multiSortMeta.findIndex(meta => meta.field === field);
if(index >= 0)
this.d_multiSortMeta[index] = meta;
else
this.d_multiSortMeta.push(meta);
if (index >= 0) {
if (this.removableSort && (this.d_multiSortMeta[index].order * -1 === this.defaultSortOrder))
this.d_multiSortMeta.splice(index, 1);
else
this.d_multiSortMeta[index] = {field: field, order: this.d_multiSortMeta[index].order * -1};
}
else {
this.d_multiSortMeta.push({field: field, order: this.defaultSortOrder});
}
this.d_multiSortMeta = [...this.d_multiSortMeta];
},
Expand Down
6 changes: 6 additions & 0 deletions src/views/treetable/TreeTableDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,12 @@ export default {
<td>single</td>
<td>Defines whether sorting works on single column or on multiple columns.</td>
</tr>
<tr>
<td>removableSort</td>
<td>boolean</td>
<td>false</td>
<td>When enabled, columns can have an un-sorted state.</td>
</tr>
<tr>
<td>filters</td>
<td>object</td>
Expand Down

0 comments on commit 45d62fd

Please sign in to comment.