ViewUI
ViewUI copied to clipboard
[Bug Report]Table with slot-scope sort does not work
Environment
Vue 2.6.11 | Iview 4.2.0 | Chrome 83.0.4103.116
Reproduction link
https://jsfiddle.net/ycL9ph4n/
Steps to reproduce
Use slot sortable column
What is expected?
The sort works properly
What is actually happening?
The sort is not recognizing the values
I also meet this problem.
"vue": "^2.6.11", "view-design": "^4.2.0", Chrome 83.0.4103.61 x64
Code is as below:
<Table
ref="stuListTable"
border
highlight-row
:columns="stuCol"
:data="stuData"
@on-row-dblclick="showByDblClickTable"
>
<template slot-scope="{ row }" slot="Dob">{{ formatDate(row.Dob) }}</template>
</template>
</Table>
formatDate(date) {
let dateFormatted = "";
if (!date) {
dateFormatted = "";
} else {
dateFormatted = moment(date).format("YYYY-MM-DD");
if (moment(date).format("YYYY-MM-DD") == "Invalid date") {
dateFormatted = "";
}
}
return dateFormatted;
},
this.stuCol.push({
title: "出生年月",
slot: "Dob",
sortable: true,
width: 120
});
Table can be sorted by Dob, but it is not in correct sequence.
Steps to reproduce
Use slot sortable column
What is expected?
The sort works properly
What is actually happening?
The sort is not recognizing the values
@antonelepfl @Alvinpro 1、加上 key 排序就正常了,虽然 slot 和 key 冗余了
{
title: "出生年月",
slot: "Dob",
key: "Dob",
sortable: true,
width: 120
}
2、如果你的 Dob 是特殊时间格式,还需要使用 sortMethod
{
title: "出生年月",
slot: "Dob",
key: "Dob",
sortable: true,
width: 120,
sortMethod: (a, b, type) => {
const formatA = formatDate(a)
const formatB = formatDate(b)
if (type === 'asc') {
return formatA >= formatB ? 1 : -1
} else {
return formatA <= formatB ? 1 : -1
}
}
}