I am using react-table to display some rows, each row has a subcomponent, which just renders some more "subrows." However, you have to click the row in order to show the subrows. React-table does not have a setting to have then expanded by default. There is some discussion out there on doing this but I can't seem to make anything work with my example.
Current looks like this on load:
After clicking on each row (how im trying to get it to look by default)
Table.js
import React, { Component } from 'react';
import ReactTable from 'react-table';
import { columns, subComponent } from './tableSetup';
class Table extends Component {
constructor(props) {
super(props);
}
render() {
return (
<ReactTable data={ data }
columns={ columns }
SubComponent={ subComponent }
expandedRows={ true }
resizable={ false }
minRows={ 1 }
pageSize={ 8 }
showPageSizeOptions={ false } />
);
}
}
export default Table;
tableSetup.js with exampe data import React from 'react';
export const columns = [
{
Header: () => (
<div />
),
accessor: 'name',
maxWidth: 300,
Cell: row => (
<div className='first-column'>{row.value}</div>
)
}
];
export const subComponent = row => {
return (
<div>
{row.original.types.map((type, id) => {
return (
<div className='subRow' key={ id }>{ type.name }</div>
);
})}
</div>
);
};
export const data = [
{
id: '12345',
name: 'sports',
types: [
{
name: 'basketball',
id: '1'
},
{
name: 'soccer',
id: '2'
},
{
name: 'baseball',
id: '3'
}
]
},
{
id: '678910',
name: 'food',
types: [
{
name: 'pizza',
id: '4'
},
{
name: 'hamburger',
id: '5'
},
{
name: 'salad',
id: '6'
}
]
}
];