I am trying to print the boolean and timestamp values that are returned by some API. I am unable to do the same. Help would be appreciated
column config object:
<ReactTable
data={this.state.data}
columns={[
{
Header: 'Name',
accessor: 'name'
},
{
Header: 'Age>18',
accessor: d => d.isAgeAbove18.toString(); // this does not work
},
{
Header: 'TimeStamp',
accessor: d => d.timeVal.toString(); // this does not work
},
]}
/>
Looking at the React tables documentation, it says that you need to provide the id property whenever the accessor type is not a string. So, I the updated format should be this.
columns={[
{
Header: 'Name',
accessor: 'name'
},
{
id:'age' // add this
Header: 'Age>18',
accessor: d => d.isAgeAbove18.toString();
},
{
id: 'timestamp' // add this
Header: 'TimeStamp',
accessor: d => d.timeVal.toString();
},
]}
I think this is the best solution in case you are using filters,
id: 'available',
Header: "Available",
accessor: d => { return d.available ? 'Available' : 'Not available' },
filterable: true,
Filter: () => (
<select className='form-control' value={this.state.availability_value} onChange={(e) => this.applyFilter(e.target.value)} >
<option value={`{ "available": "" }`}>Select</option>
<option value={`{ "available": "" }`}>All</option>
<option value={`{ "available": "1" }`}>Available</option>
<option value={`{ "available": "0" }`}>Not available</option>
</select>
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With