reactjs - 如何使用打字稿反应使数据表中的自动增量编号列发生反应?
问题描述
我正在尝试做一些简单的事情:在 primereact / components / datatable / DataTable 列上显示行号。
问题是似乎唯一可行的方法是添加一个带有索引的数据字段,如果打开排序,这些索引会被打乱。
我不想添加数据字段。
<DataTable
value={this.props.state.communitylist}
paginator={true}
rows={10}
rowsPerPageOptions={[10, 20, 30, 50]}
header={header}
globalFilter={this.state.globalFilter}
scrollable={true}
responsive={true}>
<Column field="shortId" header="ShortId"/>
<Column field="country" header="Country"/>
<Column field="city" header="City"/>
<Column field="partners" header="Partners"/>
<Column header="Action" body={this.actionButtons}
style={{textAlign: 'center', width: '10em'}}/>
</DataTable>
如您所见,第一列是shortId
. 这是数据库字段。我不想这样。
我想在没有数据库字段而不是shortId
.
理想情况下,会有一种方法可以做到这一点,但我似乎找不到任何方法。
解决方案
您可以访问一个 rowIndex 属性。它在 body 函数的第二个参数中。
下面的例子:
<Column header="Index" body={(_, { rowIndex }) => rowIndex + 1} />
推荐阅读
- react-native - 将父数据传递到子屏幕(抽屉导航)
- django - Django drf-yasg ViewSet 错误:AttributeError:“list”对象没有属性“items”
- python - 当打印语句在python的一个类中时如何只打印一次语句
- c++ - 鼠标跟踪不起作用在主小部件的小部件中
- reactjs - 如何修复部署在 github 页面上的 react 应用程序的 404?
- flutter - 我想建立搜索栏以按标题获取用户帖子
- javascript - JQuery 过滤器按数组选择选项
- javascript - Using PHP to validate range slider
- d3.js - 日期未定义
- javascript - 从 Firebase 管理员向客户端发送自定义令牌