【问题标题】:Create clickable buttons on react-bootstrap-table on cell在单元格上的 react-bootstrap-table 上创建可点击按钮
【发布时间】:2018-02-05 06:42:30
【问题描述】:

我正在尝试通过单击 react-bootstrap-table 中的“单击此处查看”按钮来加载模式

有人可以帮我吗?如何加载单元格的模态 onClick

【问题讨论】:

标签: reactjs react-bootstrap-table


【解决方案1】:

为您的按钮创建一个组件,在其单击处理程序中显示一个对话框。 使用 react-bootstrap-table,您可以在 header-column 定义中为单元格传递数据格式化函数,以呈现此按钮。

以下示例使用 react-bootstrap-dialog (https://github.com/akiroom/react-bootstrap-dialog/) 作为模态。

import React, { Component } from 'react';
import { Button } from 'react-bootstrap';
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
import Dialog from 'react-bootstrap-dialog';

class YourTable extends Component {

    cellButton(cell, row, enumObject, rowIndex) {
        return (
            <YourButton cell={cell} row={row} rowIndex={rowIndex} />
        )
    }
    render() {
        return (
            <BootstrapTable data={yourdata}>
                <TableHeaderColumn dataField='id' isKey>Id</TableHeaderColumn>
                <TableHeaderColumn
                    dataField='sessionDetails'
                    dataFormat={this.cellButton.bind(this)}></TableHeaderColumn>
            </BootstrapTable>
        )
    }
}

class YourButton extends Component {
    constructor(props) {
        super(props);
        this.handleClick = this.handleClick.bind(this);
    }

    handleClick(cell, row, rowIndex) {
        this.dialog.show({
            body: `Confirm... "${cell}"?`,
            actions: [
                Dialog.CancelAction(),
                Dialog.OKAction(() => {
                // do whatever you want
                })
            ]
        })
   }

   render() {
        const { cell, row, rowIndex } = this.props;
        return (
            <React.Fragment>
                <Button
                    bsStyle="primary"
                    onClick={() => this.handleClick(cell, row, rowIndex)}
                >Show Info</Button>
                <Dialog ref={(el) => { this.dialog = el }} />
            </React.Fragment>
        )
    }
}

请参阅:https://allenfang.github.io/react-bootstrap-table/docs.html#dataFormat 了解更多信息,但请注意 react-bootstrap-table 已弃用。

【讨论】:

    猜你喜欢
    • 2012-09-15
    • 2019-11-08
    • 1970-01-01
    • 2022-07-27
    • 2014-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多