我有一个名为" link“的列有链接,但排序对此列不起作用。请帮帮忙
data = [
{
id: 1,
name: 'Leanne Graham',
username: 'Bret',
link: '<a href="http://www.google.com">Google</a>',
},
{
id: 2,
name: 'Ervin Howell',
username: 'Antonette',
link: '<a href="https://github.com/akveo/ng2-admin">Ng2 Admin</a>',
}];
settings = {
columns: {
id: {
title: 'ID',
},
name: {
title: 'Full Name',
},
username: {
title: 'User Name',
},
link: {
title: 'Link',
type: 'html',
},
},发布于 2021-05-18 15:17:00
我不熟悉ng2-smart-table,但我猜排序是使用整个链接值进行排序,而不是显示文本。
不管是不是这样,试着看看compareFunction
link: {
title: 'Link',
type: 'html',
compareFunction(direction: any, a: any, b: any) => {
//gets the text in the link element
let aText = $("<div></div>").html(a).find("a").text().toLowerCase();
let bText = $("<div></div>").html(b).find("a").text().toLowerCase();
if (aText < bText) {
return -1 * direction;
}
if (aText > bText) {
return direction;
}
return 0;
}
}发布于 2021-05-20 23:55:55
https://stackoverflow.com/questions/67580901
复制相似问题