问题
I am looking for the solution where I would map the data to every table row with accordion where by clicking on it, it would expand the <div>
under the table row.
this is the mapping of data to TableRow what I have so far:
var mappedOrders = sortedOrders.map(order => {
return (
<Table.Row key={order._id}>
<Table.Cell>{order.address.lastName + " " + order.address.firstName}</Table.Cell>
<Table.Cell>{order.payment.vs}</Table.Cell>
<Table.Cell>
<Button onClick={this.openOrderDetails(order)} style={{ padding: '0.3em' }} size='medium' icon='edit' />
<Button style={{ padding: '0.3em' }} size='medium' icon='check' />
<Button style={{ padding: '0.3em' }} size='medium' icon='file pdf' />
<Button style={{ padding: '0.3em' }} size='medium' icon='shipping fast' />
<Button style={{ padding: '0.3em' }} size='medium' icon='close' />
</Table.Cell>
</Table.Row>
)
}
)
<Table compact padded selectable basic='very'>
<Table.Header>
<Table.Row style={{ textAlign: 'center' }}>
<Table.HeaderCell width={2}>Name</Table.HeaderCell>
<Table.HeaderCell width={1}>VS</Table.HeaderCell>
<Table.HeaderCell width={3}>Actions</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
{mappedOrders}
</Table.Body>
</Table>
回答1:
This worked for me (not the same use case as you)
But the idea is to have the accordion act "as" a table.body, then the panels act as the rows. This makes it work
<Table>
<Table.Header>
<Table.HeaderCell>Node Type</Table.HeaderCell>
<Table.HeaderCell>Display</Table.HeaderCell>
</Table.Header>
<Accordion
fluid={true}
as={Table.Body}
panels={this.props.visibleNodes.map(n => {
return {
key: n.id,
class: "tr",
title: {
as: Table.Row,
className: "",
children: [
<Table.Cell key={`${n.id}_type`}>{n._node_type}</Table.Cell>,
<Table.Cell key={`${n.id}_display`}>{n._display}</Table.Cell>
]
},
content: {
children: JSON.stringify(n.properties)
}
};
})}
/>
</Table>
来源:https://stackoverflow.com/questions/53240115/semantic-ui-react-map-accordion-in-every-table-row