我在我的应用程序中为表使用了一个名为 react-data-table-component 的库。一切都很顺利,但是我需要添加一个列,该列将在我的表中显示序列号。序列号始终从 1 开始到照片数组中的对象总数。
const columns = [
{
name: '#',
selector: 'id',
cell: (row) => <span>{I need to show serial number here}</span>
},
{
name: 'Name',
selector: 'photo_link',
sortable: true,
}
... // Other fields
]
<DataTable
columns={columns}
data={photos}
paginationTotalRows={total_photos}
列数组中的单元格键仅将行作为参数,并且它具有当前对象,但我无法获取对象的索引。
我在数组的每个对象中都有 id 字段,但这不是我需要的顺序。我该如何解决这个问题?