Skip to content

Commit b2fc6fb

Browse files
committed
Improvement - VueUiTableSparkline - Improve column sorting behavior
1 parent b664a47 commit b2fc6fb

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,12 @@ function orderDatasetByIndex(th, index) {
221221
selectedDataIndex.value = index;
222222
currentAdditionalSort.value = undefined;
223223
224-
// Maybe for later:
225-
// if (currentSortOrder.value === 1) {
226-
// currentSortOrder.value = -1;
227-
// currentSortingIndex.value = undefined;
228-
// restoreOrder();
229-
// return;
230-
// }
224+
if (currentSortOrder.value === 1) {
225+
currentSortOrder.value = -1;
226+
currentSortingIndex.value = undefined;
227+
restoreOrder();
228+
return;
229+
}
231230
232231
isSorting.value = true;
233232
currentSortingIndex.value = index;
@@ -309,8 +308,19 @@ function orderDatasetByAttribute(attribute) {
309308
if (!mutableDataset.value || mutableDataset.value.length === 0) return;
310309
if (!hasAdditionalSorting(attribute)) return;
311310
312-
currentAdditionalSort.value = attribute;
311+
if (currentAdditionalSort.value !== attribute) {
312+
currentAdditionalSort.value = undefined;
313+
}
314+
313315
currentSortingIndex.value = undefined;
316+
317+
if (sortOrders.value[attribute] === -1 && currentAdditionalSort.value) {
318+
currentAdditionalSort.value = undefined;
319+
restoreOrder();
320+
return;
321+
}
322+
323+
currentAdditionalSort.value = attribute;
314324
isSorting.value = true;
315325
316326
sortOrders.value[attribute] = sortOrders.value[attribute] === -1 ? 1 : -1;
@@ -396,6 +406,10 @@ function getArrowOpacity(index, th) {
396406
}
397407
}
398408
409+
function resetOnClickOutside() {
410+
FINAL_CONFIG.value.resetSortOnClickOutside && restoreOrder();
411+
}
412+
399413
defineExpose({
400414
generatePdf,
401415
generateImage,
@@ -434,7 +448,7 @@ defineExpose({
434448
<tr
435449
role="row"
436450
class="vue-ui-data-table__thead-row"
437-
v-click-outside="restoreOrder"
451+
v-click-outside="resetOnClickOutside"
438452
:style="{
439453
backgroundColor: FINAL_CONFIG.thead.backgroundColor,
440454
color: FINAL_CONFIG.thead.color
@@ -456,7 +470,6 @@ defineExpose({
456470
justifyContent: FINAL_CONFIG.thead.textAlign
457471
}">
458472
<span>{{ FINAL_CONFIG.translations.serie }}</span>
459-
460473
<BaseIcon
461474
:size="18"
462475
v-if="FINAL_CONFIG.sortedSeriesName"
@@ -649,7 +662,6 @@ defineExpose({
649662
padding: '0',
650663
}" class="vue-ui-data-table__tbody__td sticky-col">
651664
<SparkLine
652-
:key="`sparkline_${i}_${sparkStep}`"
653665
@hoverIndex="({ index }) => hoverSparkline({ dataIndex: index, serieIndex: i })
654666
"
655667
:height-ratio="FINAL_CONFIG.sparkline.dimensions.heightRatio"

0 commit comments

Comments
 (0)