fix datatable sorting issue

This commit is contained in:
pa
2025-12-22 21:01:39 +09:00
committed by Natsumi
parent fbfb31b667
commit 9b20d62a90
2 changed files with 35 additions and 18 deletions

View File

@@ -110,26 +110,43 @@
const detectCreatedAtOrder = (src) => {
if (!Array.isArray(src) || src.length <= 2) return null;
let couldBeAsc = true;
let couldBeDesc = true;
const start = Math.max(1, src.length - effectivePageSize.value - 1);
for (let i = start; i < src.length; i++) {
const a = src[i - 1]?.created_at;
const b = src[i]?.created_at;
if (typeof a !== 'string' || typeof b !== 'string') continue;
if (a > b) {
couldBeAsc = false;
} else if (a < b) {
couldBeDesc = false;
}
if (!couldBeAsc && !couldBeDesc) {
return null;
const detectOrderInRange = (startIndexInclusive, endIndexInclusive) => {
let couldBeAsc = true;
let couldBeDesc = true;
const start = Math.max(1, startIndexInclusive);
const end = Math.min(endIndexInclusive, src.length - 1);
for (let i = start; i <= end; i++) {
const a = src[i - 1]?.created_at;
const b = src[i]?.created_at;
if (typeof a !== 'string' || typeof b !== 'string') continue;
if (a > b) {
couldBeAsc = false;
} else if (a < b) {
couldBeDesc = false;
}
if (!couldBeAsc && !couldBeDesc) {
return null;
}
}
if (couldBeAsc) return 'asc';
if (couldBeDesc) return 'desc';
return null;
};
const windowSize = Math.min(Math.max(effectivePageSize.value + 1, 25), 200);
const headEnd = Math.min(src.length - 1, windowSize);
const tailStart = Math.max(1, src.length - windowSize);
const headOrder = detectOrderInRange(1, headEnd);
const tailOrder = detectOrderInRange(tailStart, src.length - 1);
if (headOrder && tailOrder && headOrder !== tailOrder) {
return null;
}
if (couldBeAsc) return 'asc';
if (couldBeDesc) return 'desc';
return null;
return tailOrder || headOrder;
};
const throttledData = ref(asRawArray(data.value));

View File

@@ -50,7 +50,7 @@
</div>
<DataTable v-bind="notificationTable" ref="notificationTableRef" class="notification-table">
<el-table-column :label="t('table.notification.date')" prop="created_at" :sortable="true" width="130">
<el-table-column :label="t('table.notification.date')" prop="created_at" width="130">
<template #default="scope">
<el-tooltip placement="right">
<template #content>