使用ant design vue Table组件遇见的问题记录

1.首先是给表格加自增序号

{
    title: "序号",
    customRender: (text, record, index) => `${index + 1}`,
  },

这样就加上了

2.然后是ant没有key值控制台报错

如果有id或者唯一属性可以把rowkey设置为唯一属性
查了一下也不一定是必须要key或者rowkey
可以用几个方法

rowKey : (record,index)=> index

或者

rowKey : record => record.dataIndex,

这是我的写法

<a-table :columns="columns" :rowKey='(record, index) => index' :data-source="list" :pagination="paginationOpt">
  </a-table>

报错解决

3.表格升序降序的排序功能

只需要在需要的那一列中开启

{
    title: "提交量",
    dataIndex: "total",
    key: "total",
    sorter: (a, b) => b.total > a.total,
    sortDirections: ["ascend", "descend"],
  },

 

posted @ 2023-08-24 10:43  土小狗  阅读(152)  评论(0编辑  收藏  举报