Add an index column to antd-table

really speechless so speechless

The table displays the # column, which was originally an id. The result is not required to display the order. The order is the order. It is very easy to arrange in the backend.

In the end, I had to let the front end line up, just shoot it, I feel that the function realized in the end is very tasteless...

Without further ado, let's serve!

After trying a lot, the most suitable and simple one is to directly manipulate the data, and inject the index directly into the data set, or it cannot meet the requirements.

1.

const resData = res.data?.records || []

 const  myIndexedData = resData.map((el,index) => ({index, ...el}))

2. Just change it in the columns

const columns = [

    {

      title: '#',

      dataIndex: 'index',

      valueType: 'digit',

      search: false,

      width: 70,

    //   render: (_, record) => {

    //     console.info('record',record)

    //     // return <div>{record.name}</div>;

    // }

    },

...

]

I also tried to change it directly in the columns, but the effect is not what I want. If there is no index column, let’s add it obediently.

The disadvantage is that when paging, it will still restart, but in fact, it can not be restarted, forget it. how easy how come

Guess you like

Origin blog.csdn.net/chhpearl/article/details/126244908