【问题标题】:Adding serial number to the react bootstrap table 2将序列号添加到反应引导表 2
【发布时间】:2021-10-12 07:48:03
【问题描述】:

我在我的项目中使用react-bootstrap 表,我想在我的表中添加一个带有序列号的列,但无法生成序列号,所以请指导我如何操作。 任何帮助将不胜感激,并提前感谢您的帮助。

目前正在编写以下代码以生成序列号,但未获取列中的数字。

const columns = [
{ text: 'Sn',
  cell: (row, index) => index + 1 ,
  headerAttrs: { width: "50px" }
},
{
  text: "Customer Id",
  dataField: "customerId",
  classes: "alignment"
},
{
  text: "Email",
  dataField: "email",
  classes: "alignment",
  headerAttrs: { width: "200px" }
},
{
  text: "Role",
  dataField: "role"
},
{
  text: "Date Created",
  dataField: "dateCreated",
  formatter: dateFormatter
},
{
  text: "Customer Type",
  dataField: "plan"
},
];

【问题讨论】:

  • 请展示你迄今为止尝试过的所有内容
  • 我已经用代码编辑了我的帖子。

标签: reactjs react-bootstrap-table react-bootstrap-table2


【解决方案1】:

您可以使用以下格式化程序属性来获取相应的序列号。

{
  dataField: 'sl.no',
  text: 'Sl no.',
  formatter: (cell, row, rowIndex, formatExtraData) => {
    return rowIndex + 1;
  },
  sort: true,
},

【讨论】:

  • 非常感谢 Dev.. 它可以工作
  • 欢迎@JatinPanday
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-13
  • 1970-01-01
  • 2019-07-02
  • 2020-04-17
  • 2019-07-19
  • 1970-01-01
相关资源
最近更新 更多