react-bootstrap-table icon indicating copy to clipboard operation
react-bootstrap-table copied to clipboard

How to access dataField in dataFormat?

Open NilapuAnusha opened this issue 8 years ago • 2 comments

I have below code render() { const col = [ 'id', 'name', 'price' ]; return ( <BootstrapTable data={ products } keyField={ col[0] }> { col.map(name => <TableHeaderColumn dataField={ name }>{ name }</TableHeaderColumn>) } </BootstrapTable> ); }

Now I want to add dataFormat to TableHeaderColumn. How can I acces dataField in dataFormat to know the key?

NilapuAnusha avatar Dec 11 '17 09:12 NilapuAnusha

With inline dataFormat you have access to the enclosing scope so:

col.map( name =>
    <TableHeaderColumn
        dataFormat={
                (cell, row, formatExtraData, index) => {
                    name <-- you can access it
                }
        }
        ....

pastinepolenta avatar Dec 11 '17 15:12 pastinepolenta

Have you found the answer? Please let me know if you have any solutions to this issue.

terrygreen0606 avatar Sep 02 '20 04:09 terrygreen0606