简体   繁体   English

如何在反应表中添加标题

[英]how to add title to react-table

I am using react-table and need to add custom titles to a single table. 我正在使用react-table,需要将自定义标题添加到单个表中。 I cannot figure out how to do this by looking over the examples and docs. 我无法通过查看示例和文档来弄清楚该如何做。 Here is what my table currently looks like. 这是我的桌子目前的样子。

当前表

Here is what I need it to look like. 这是我需要的外观。

所需表

And here is my config for the table. 这是我对该表的配置。

    [
  {
    Header: '',
    columns: []
  },
  {
    Header: '',
    columns: []
  },
  {
    Header: 'Avg Sales',
    columns: []
  },
  {
    Header: 'Project to Date',
    columns: []
  },
  {
    Header: '',
    columns: [
      {
        Header: '',
        accessor: 'spacer',
        width: 35
      }
    ]
  },
  {
    Header: 'Activity & Inventory',
    columns: []
  },
  {
    Header: '',
    columns: [
      {
        Header: '',
        accessor: 'spacer',
        width: 35
      }
    ]
  },
  {
    Header: 'Additional Data Entered',
    columns: []
  }
]

Seems like in columns every object can have a field header and a field columns that haves an array with objects with the same structure. 好像在列中一样,每个对象都可以具有一个字段标题和一个字段列,这些字段的数组包含具有相同结构的对象。 So in your case you would need something like, so what you need is just to split your objects like: 因此,在您的情况下,您将需要类似的东西,因此您需要的只是拆分对象,例如:

[{
  Header: 'Title 1',
  columns: [...], //subgroup 1
 },
 {
  Header: 'Title 2',
  columns: [...], //subgroup 2
 },
]

If it doesn't solve your problem, you could add the elements separately then adjust with CSS. 如果不能解决问题,则可以单独添加元素,然后使用CSS进行调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM