Skip to content

Commit 5fc1cda

Browse files
committed
Fix - VueUiTableSparkline - Fixed wrong reordering of sparklines when sorting columns
1 parent 7a0c1a7 commit 5fc1cda

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const step = ref(0);
3838
const defaultConfig = ref(mainConfig.vue_ui_table_sparkline);
3939
const isPrinting = ref(false);
4040
const isImaging = ref(false);
41+
const sparkStep = ref(0)
4142
4243
const tableConfig = computed(() => {
4344
return useNestedProp({
@@ -132,6 +133,10 @@ const datasetWithOrders = computed(() => {
132133
133134
const mutableDataset = ref(datasetWithOrders.value)
134135
136+
const maxSeries = computed(() =>{
137+
return Math.max(...mutableDataset.value.map(ds => (ds.values || []).length))
138+
})
139+
135140
const sortIndex = ref(undefined)
136141
const isSorting = ref(false);
137142
const currentSortingIndex = ref(undefined);
@@ -163,7 +168,8 @@ function orderDatasetByIndex(index) {
163168
164169
const sortedDataset = sortedIndices.map(i => datasetWithOrders.value[i]);
165170
166-
mutableDataset.value = sortedDataset
171+
mutableDataset.value = sortedDataset;
172+
sparkStep.value += 1
167173
}
168174
169175
const maxSeriesLength = computed(() => {
@@ -373,7 +379,7 @@ defineExpose({
373379
<span>{{ tr.name ?? "-" }}</span>
374380
</div>
375381
</td>
376-
<td role="cell" v-for="(td, j) in tr.values" :style="{
382+
<td role="cell" v-for="(_, j) in maxSeries" :style="{
377383
outline: tableConfig.tbody.outline,
378384
fontSize: `${tableConfig.tbody.fontSize}px`,
379385
fontWeight: tableConfig.tbody.bold ? 'bold' : 'normal',
@@ -393,7 +399,7 @@ defineExpose({
393399
? '3px'
394400
: '',
395401
}" :data-cell="colNames[j]" class="vue-ui-data-table__tbody__td" @pointerenter="selectedSerieIndex = i; selectedDataIndex = j">
396-
{{ Number(td.toFixed(tableConfig.roundingValues)).toLocaleString() }}
402+
{{ [null, undefined].includes(tr.values[j]) ? '-' : Number(tr.values[j].toFixed(tableConfig.roundingValues)).toLocaleString() }}
397403
</td>
398404
<td role="cell" v-if="tableConfig.showTotal" :style="{
399405
outline: tableConfig.tbody.outline,
@@ -425,7 +431,7 @@ defineExpose({
425431
fontWeight: tableConfig.tbody.bold ? 'bold' : 'normal',
426432
textAlign: tableConfig.tbody.textAlign,
427433
}" class="vue-ui-data-table__tbody__td sticky-col">
428-
<SparkLine @hoverIndex="({ index }) => hoverSparkline({ dataIndex: index, serieIndex: i })
434+
<SparkLine :key="`sparkline_${i}_${sparkStep}`" @hoverIndex="({ index }) => hoverSparkline({ dataIndex: index, serieIndex: i })
429435
" :dataset="tr.sparklineDataset" :showInfo="false" :selectedIndex="selectedDataIndex" :config="{
430436
type: tableConfig.sparkline.type,
431437
style: {

0 commit comments

Comments
 (0)