0

我正在使用反应数据表组件,我想在一个标题下显示 2 个字段。但问题是我不知道使用 react-data-table-component 的正确方法,并且 react-data-table-component 的指令不包括这样的例子。

所以我想知道我们是否可以在一列下使用两个选择器。

下面是我的代码:

{
  name:<div style={{ cursor: 'context-menu' , marginRight:'80px'}}>Implementation</div>,
  selector: 'ImplementationStatus',
  selector: 'DoneDate',

  ignoreRowClick: true,
  cell: row => (
  <div>
  <div style={{display: 'inline-block',marginRight:'10px',color:row.ImplementationStatus == 0 ? "red" : (row.ImplementationStatus == 1 ? "#fe9810" : (row.ImplementationStatus == 2 ? "green" : "black"))}}>{row.ImplementationStatus == 0 ? <div style={{marginRight:'5px'}}>NOT STARTED</div> : (row.ImplementationStatus == 1 ? <div style={{marginRight:'20px'}}>UNDERWAY</div> : (row.ImplementationStatus == 2 ? "IMPLEMENTED" : ""))}</div>
  
    <div className="align-middle text-center" style={{display: 'inline-block',paddingLeft:'0px'}}>
      <Input style={{ width: '167px',fontSize:'15px', height: '30px',backgroundColor:this.state.isManager === true || this.state.isAdmin===true ?'#FFFFFF':'#DCDCDC'}}
        type="date"
        readOnly={this.state.isManager === true || this.state.isAdmin === true ? false : true}
        placeholder="Enter Done Date"
        value={row.DoneDateVendorDisplay == null ? "2020-01-01" : row.DoneDateVendorDisplay}
        min="2020-01-01"
        max={currentDate}
      /></div>
      </div>
  ),
  center: true,
  width: 'auto',
},
4

1 回答 1

2

列 API 的选择器属性可以是字符串或函数。在下面的示例中,我将“firstName”和“lastName”结合起来生成“name”列

<DataTable
  columns={[
    {
      name: 'Name',
      selector: row => `${ row.firstName } ${ row.lastName }`
    },
    {
      name: 'Business Number',
      selector: 'businessNumber'
    },
    {
      name: 'Type',
      selector: 'type'
    }
  ]}
/>
于 2021-04-24T09:30:48.163 回答