Semantic UI (React) map accordion in every table row

心已入冬 提交于 2021-02-10 15:39:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!