AllenFang / react-bootstrap-table

A Bootstrap table built with React.js
https://allenfang.github.io/react-bootstrap-table/
MIT License
2.23k stars 782 forks source link

How to access dataField in dataFormat? #1802

Open NilapuAnusha opened 6 years ago

NilapuAnusha commented 6 years ago

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?

pastinepolenta commented 6 years ago

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
                }
        }
        ....
terrygreen0606 commented 4 years ago

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