美文网首页
iview中使用表格sortable属性后排序不生效的解决方法

iview中使用表格sortable属性后排序不生效的解决方法

作者: Bior | 来源:发表于2020-04-20 21:59 被阅读0次

在iview项目的表格中使用了sortable属性后发现排序不正常


{
  title: '创建时间',
  minWidth: 140,
  align: 'center',
  sortable: true,
  render(h, params) {
    return h('span', new Date(params.row.createDate).Format('yy-MM-dd hh:mm'));
  }
}

其中 Format函数是将后端返回的时间戳转换为 "2019-04-09 10:48" 格式

虽然加了sortable属性,但是发现排序后顺序还是不对,有的行并没有按照应有的顺序排序

预计是在数据进行Format转化后才排序,而不是直接拿后端的时间戳排序

解决办法:

虽然用了render函数,key熟悉可以不加了,但是为了排序正常,还是要把key加上

{
  title: '创建时间',
  minWidth: 140,
  align: 'center',
  sortable: true,
  key: 'createDate',
  render(h, params) {
    return h('span', new Date(params.row.createDate).Format('yy-MM-dd hh:mm'));
  }
}

这样就正常了

相关文章

网友评论

      本文标题:iview中使用表格sortable属性后排序不生效的解决方法

      本文链接:https://www.haomeiwen.com/subject/szysihtx.html