【问题标题】:React-Table Column Headers Displaying VerticallyReact-Table 列标题垂直显示
【发布时间】:2019-02-25 18:38:18
【问题描述】:

我正在使用 React-Table 模块来创建一个表。到目前为止,我有以下内容:

<div>
    <ReactTable
    columns={[{columns :
        [{
          Header: "Time",
          accessor: "time", //name of field in table
        },
        {
          Header: "Weight",
          accessor: "weight",
        }
      ]}]}
    />
</div>

但是,我的列标题垂直显示如下:

时间

重量

我希望它们按预期水平显示。

【问题讨论】:

    标签: reactjs react-table


    【解决方案1】:

    根据documentation,每个列标题都是一个对象数组,因此您传递给它的每个对象都会有一个水平显示的标题。在您的示例中,您只传递了 columns 支持一个对象,尝试将其安排得更像文档示例:

     const columns = [{
            Header: 'Name',
            accessor: 'name' // String-based value accessors!
          }, {
            Header: 'Age',
            accessor: 'age',
            Cell: props => <span className='number'>{props.value}</span> // Custom cell components!
          }, {
            id: 'friendName', // Required because our accessor is not a string
            Header: 'Friend Name',
            accessor: d => d.friend.name // Custom value accessors!
          }, {
            Header: props => <span>Friend Age</span>, // Custom header components!
            a
    
    ccessor: 'friend.age'
      }]
    

    【讨论】:

    • 感谢您的回复;但它没有用。我将此代码放入组件中。组件的 css 是否有可能覆盖 react-table css?
    • 您可以在沙箱中重新创建代码,但可能性极小。例如codesandbox.io,比张贴链接,我可以尝试帮助
    • 感谢您的回复!我最终改用引导表,效果很好。
    猜你喜欢
    • 1970-01-01
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 2021-06-12
    • 2019-01-17
    • 1970-01-01
    相关资源
    最近更新 更多