首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对于在ng2智能表angular中具有列数据超链接的列,排序不起作用

对于在ng2智能表angular中具有列数据超链接的列,排序不起作用
EN

Stack Overflow用户
提问于 2021-05-18 14:19:34
回答 2查看 97关注 0票数 0

我有一个名为" link“的列有链接,但排序对此列不起作用。请帮帮忙

代码语言:javascript
复制
  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',
  
  },
},

hyperlink example in ng2-smart-table

EN

回答 2

Stack Overflow用户

发布于 2021-05-18 15:17:00

我不熟悉ng2-smart-table,但我猜排序是使用整个链接值进行排序,而不是显示文本。

不管是不是这样,试着看看compareFunction

代码语言:javascript
复制
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;
  }
}
票数 0
EN

Stack Overflow用户

发布于 2021-05-20 23:55:55

也许这能帮到你enter link description here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67580901

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档