【发布时间】:2022-01-02 17:46:33
【问题描述】:
我在 vueJS 中有一个 v-data-table,其中包含一些数字列和一些字符串列。 在每一列中,一些值为空。 我正在尝试创建一个自定义排序函数,该函数将最后放置空值。 这是我迄今为止尝试过的:
<v-data-table
:headers="[
{ text: 'Name', value: 'name' },
{ text: 'Date of Birth', value: 'dateofbirth_fmt' },
{ text: 'Team', value: 'team_name' },
{
text: 'dp1 (string)',
value: 'dp1',
},
{
text: 'dp2 (Numeric),
value: 'dp2',
}
]"
:items="filteredPlayersData"
item-key="_id"
class="elevation-1"
:custom-sort="customSort"
/>
还有这个功能
customSort(items, index, isDesc) {
items.sort((a, b) => {
if (!isDesc[0]) {
return (a[index] != null ? a[index] : Infinity) >
(b[index] != null ? b[index] : Infinity)
? 1
: -1;
} else {
return (b[index] != null ? b[index] : -Infinity) >
(a[index] != null ? a[index] : -Infinity)
? 1
: -1;
}
});
return items;
}
它适用于这个数字列 (dp1),但不适用于字符串一 (dp2)。 任何想法如何完成这项工作?
【问题讨论】:
标签: javascript vue.js sorting vuetify.js