scinote-web/app/javascript/vue/shared/datatable/tableHeader.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

export default {
template: `
2024-02-19 20:01:37 +08:00
<div class="w-full grid items-center gap-2 grid-cols-[auto_1.5rem]"
:class="{'cursor-pointer': params.enableSorting}"
:data-e2e="'e2e-CO-TableHeader-' + params.column.colId "
2023-12-11 16:18:22 +08:00
@click="onSortRequested((activeSort == 'asc' ? 'desc' : 'asc'), $event)">
<div v-if="params.html" class="customHeaderLabel truncate" v-html="params.html"></div>
<div v-else class="customHeaderLabel truncate">{{ params.displayName }}</div>
2024-02-01 18:45:13 +08:00
<div v-if="activeSort == 'asc'" class="customSortDownLabel text-sn-black">
<i class="sn-icon sn-icon-sort-up"></i>
</div>
2024-02-01 18:45:13 +08:00
<div v-if="activeSort == 'desc'" class="customSortUpLabel text-sn-black">
<i class="sn-icon sn-icon-sort-down"></i>
</div>
</div>
`,
data() {
return {
activeSort: null
};
},
beforeMount() {},
mounted() {
this.params.column.addEventListener('sortChanged', this.onSortChanged);
this.onSortChanged();
},
methods: {
onSortChanged() {
this.activeSort = null;
if (this.params.column.isSortAscending()) {
this.activeSort = 'asc';
} else if (this.params.column.isSortDescending()) {
this.activeSort = 'desc';
}
},
onSortRequested(order, event) {
if (!this.params.enableSorting) return;
this.params.setSort(order, event.shiftKey);
}
}
};