Skip to content

Commit 988c0aa

Browse files
committed
Improvement - VueUiTableSparkline - Change arrow icons & improve sorting states
1 parent d6ea88f commit 988c0aa

File tree

1 file changed

+55
-20
lines changed

1 file changed

+55
-20
lines changed

src/components/vue-ui-table-sparkline.vue

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -199,20 +199,27 @@ const maxSeries = computed(() =>{
199199
const sortIndex = ref(undefined)
200200
const isSorting = ref(false);
201201
const currentSortingIndex = ref(undefined);
202-
const currentSortOrder = ref(-1);
202+
const currentSortOrder = ref(1);
203203
204204
function restoreOrder() {
205205
isSorting.value = false;
206206
currentSortingIndex.value = undefined;
207207
currentAdditionalSort.value = undefined;
208-
currentSortOrder.value = -1;
208+
currentSortOrder.value = 1;
209+
sortStates.value.forEach(c => c.state = 1)
210+
sortOrders.value = {
211+
name: 1,
212+
sum: 1,
213+
average: 1,
214+
median: 1
215+
}
209216
mutableDataset.value = datasetWithOrders.value;
210217
}
211218
212219
function orderDatasetByIndex(th, index) {
213220
214221
if ((['name', 'sum', 'average', 'median'].includes(th.type))) {
215-
orderDatasetByAttribute(th.type);
222+
orderDatasetByAttribute(th.type, index);
216223
return;
217224
}
218225
@@ -221,8 +228,12 @@ function orderDatasetByIndex(th, index) {
221228
selectedDataIndex.value = index;
222229
currentAdditionalSort.value = undefined;
223230
224-
if (currentSortOrder.value === 1) {
225-
currentSortOrder.value = -1;
231+
if ((![null, undefined].includes(currentSortingIndex.value) && index !== currentSortingIndex.value)) {
232+
currentSortingIndex.value = undefined;
233+
restoreOrder();
234+
}
235+
236+
if (sortStates.value[index].state === 1 && currentSortingIndex.value === index) {
226237
currentSortingIndex.value = undefined;
227238
restoreOrder();
228239
return;
@@ -234,6 +245,8 @@ function orderDatasetByIndex(th, index) {
234245
const combinedValues = datasetWithOrders.value.map(series => (series.values[index] || []));
235246
236247
const sortOrder = sortIndex.value === index ? 1 : -1;
248+
sortStates.value[index].state = sortOrder;
249+
237250
currentSortOrder.value = sortOrder;
238251
if(index === sortIndex.value) {
239252
sortIndex.value = undefined
@@ -296,34 +309,44 @@ const colNames = computed(() => {
296309
});
297310
298311
const sortOrders = ref({
299-
name: -1,
300-
sum: -1,
301-
average: -1,
302-
median: -1
312+
name: 1,
313+
sum: 1,
314+
average: 1,
315+
median: 1
303316
})
304317
305318
const currentAdditionalSort = ref(undefined);
306319
307-
function orderDatasetByAttribute(attribute) {
320+
function orderDatasetByAttribute(attribute, index) {
308321
if (!mutableDataset.value || mutableDataset.value.length === 0) return;
309322
if (!hasAdditionalSorting(attribute)) return;
310323
311324
if (currentAdditionalSort.value !== attribute) {
312325
currentAdditionalSort.value = undefined;
313326
}
314327
328+
if (![null, undefined].includes(currentSortingIndex.value) && index !== currentSortingIndex.value) {
329+
restoreOrder();
330+
}
331+
315332
currentSortingIndex.value = undefined;
316333
317-
if (sortOrders.value[attribute] === -1 && currentAdditionalSort.value) {
334+
335+
if (sortOrders.value[attribute] === 1 && currentAdditionalSort.value) {
318336
currentAdditionalSort.value = undefined;
319337
restoreOrder();
320338
return;
321339
}
322-
340+
323341
currentAdditionalSort.value = attribute;
324342
isSorting.value = true;
325343
326344
sortOrders.value[attribute] = sortOrders.value[attribute] === -1 ? 1 : -1;
345+
346+
if (![null, undefined].includes(index)) {
347+
sortStates.value[index].state = sortOrders.value[attribute];
348+
}
349+
327350
const sortOrder = sortOrders.value[attribute];
328351
329352
const sortedDataset = [...mutableDataset.value].sort((a, b) => {
@@ -410,6 +433,17 @@ function resetOnClickOutside() {
410433
FINAL_CONFIG.value.resetSortOnClickOutside && restoreOrder();
411434
}
412435
436+
const sortStates = computed({
437+
get: () => {
438+
return colNames.value.map(_c => {
439+
return { state: 1 };
440+
})
441+
},
442+
set: (_) => {
443+
return _;
444+
}
445+
});
446+
413447
defineExpose({
414448
generatePdf,
415449
generateImage,
@@ -420,8 +454,7 @@ defineExpose({
420454
</script>
421455
422456
<template>
423-
<div ref="tableContainer" :class="{ 'vue-ui-responsive': isResponsive }" style="overflow: hidden" :id="`table_${uid}`">
424-
457+
<div ref="tableContainer" :class="{ 'vue-ui-responsive': isResponsive }" style="overflow: hidden" :id="`table_${uid}`">
425458
<div style="overflow: auto" @pointerleave="selectedSerieIndex = undefined; selectedDataIndex = undefined">
426459
<table data-cy="vue-data-ui-table-sparkline" class="vue-ui-data-table"
427460
:style="{ fontFamily: FINAL_CONFIG.fontFamily, position: 'relative' }">
@@ -467,13 +500,14 @@ defineExpose({
467500
flexDirection: 'row',
468501
alignItems: 'center',
469502
gap: '6px',
470-
justifyContent: FINAL_CONFIG.thead.textAlign
503+
justifyContent: FINAL_CONFIG.thead.textAlign,
504+
pointerEvents: 'none'
471505
}">
472506
<span>{{ FINAL_CONFIG.translations.serie }}</span>
473507
<BaseIcon
474-
:size="18"
508+
:size="12"
475509
v-if="FINAL_CONFIG.sortedSeriesName"
476-
:name="'sort'"
510+
:name="sortOrders.name === 1 ? 'arrowBottom' : 'arrowTop'"
477511
:stroke="FINAL_CONFIG.thead.color"
478512
:style="{
479513
opacity: currentAdditionalSort === 'name' ? 1 : 0.3
@@ -497,14 +531,15 @@ defineExpose({
497531
flexDirection: 'row',
498532
alignItems: 'center',
499533
gap: '6px',
500-
justifyContent: FINAL_CONFIG.thead.textAlign
534+
justifyContent: FINAL_CONFIG.thead.textAlign,
535+
pointerEvents: 'none'
501536
}">
502537
<span>{{ th.value }}</span>
503538
504539
<BaseIcon
505-
:size="18"
540+
:size="12"
506541
v-if="hasSorting(i) || hasAdditionalSorting(th)"
507-
:name="'sort'"
542+
:name="sortStates[i].state === 1 ? 'arrowBottom' : 'arrowTop'"
508543
:stroke="FINAL_CONFIG.thead.color"
509544
:style="{
510545
opacity: getArrowOpacity(i, th)

0 commit comments

Comments
 (0)