I am currently utilizing Material-UI's <Table/>
component and I would like to alternate row colors between blue and purple. The first row will be blue, the second row will be purple, and so on for every additional row added.
How can I dynamically switch between two colors for each new row added?
render(){
return(
<Table
multiSelectable={true}
>
<TableHeader>
<TableRow>
<TableHeaderColumn>First Name</TableHeaderColumn>
<TableHeaderColumn>Last Name</TableHeaderColumn>
<TableHeaderColumn>Color</TableHeaderColumn>
</TableRow>
</TableHeader>
<TableBody
displayRowCheckbox={true}
stripedRows
>
<TableRow style={{backgroundColor: rowIndex%2===0 ? 'blue' : 'purple'}}>
<TableRowColumn>John</TableRowColumn>
<TableRowColumn>Smith</TableRowColumn>
<TableRowColumn>Red</TableRowColumn>
</TableRow>
{tableData.map((row,index) => (
<TableRow style={{backgroundColor: index%2===0 ? 'blue' : 'purple'}}>
<TableRowColumn>{row.firstName}</TableRowColumn>
<TableRowColumn>{row.lastName}</TableRowColumn>
<TableRowColumn>{row.color}</TableRowColumn>
</TableRow>
))}
</TableBody>
</Table>
Thank you in advance