question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSX rendering dynamic TableHeaderColumn

See original GitHub issue

I am trying to dynamically generate the TableHeaderColumn within the BootstrapTable component, although cannot do it and receive an error.

The following works:

<BootstrapTable
            data={products2} striped={true} hover={true} condensed={true} columnFilter={true} pagination={true} search={true}>
            <TableHeaderColumn dataField="id" isKey={true} dataAlign="left" width="70px" dataSort={true}>#</TableHeaderColumn>
            <TableHeaderColumn dataField="carfilename" dataSort={true} width="300px">Car filename</TableHeaderColumn>
            <TableHeaderColumn dataField="local" dataSort={true} width="300px">local</TableHeaderColumn>
            <TableHeaderColumn dataField="localDev" dataSort={true} width="300px">localDEV</TableHeaderColumn>
            <TableHeaderColumn dataField="DEV" dataSort={true} width="300px">DEV</TableHeaderColumn>
            <TableHeaderColumn dataField="TRN" dataSort={true} width="300px">TRN</TableHeaderColumn>
</BootstrapTable>

However I need to generate the environment columns dynamically, but the following does not work:

<BootstrapTable data={products2} striped={true} hover={true} condensed={true} columnFilter={true} pagination={true} search={true}>
      <TableHeaderColumn dataField="id" isKey={true} dataAlign="left" width="70px" dataSort={true}>#</TableHeaderColumn><TableHeaderColumn dataField="carfilename" dataSort={true} width="300px">Car filename</TableHeaderColumn>
      {envColumns}            
</BootstrapTable>

Related code: envColumns.push(<EnvironmentHeaderColumn envname={envvalue.envName} key={envkey} />);

var EnvironmentHeaderColumn = React.createClass({
    render: function () {
        var env = this.props.envname;
        // console.log('env is ' + env);

        return (
            <TableHeaderColumn dataField={env} dataAlign="center">{env}</TableHeaderColumn>
        );
    }
});

I receive the following error in Google Chrome:

Uncaught TypeError: Cannot read property ‘children’ of undefined

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tester5commented, Sep 30, 2016

thanks very much for your help Allen. I managed to resolve some issues with column alignment (i.e. by fixing the # width) as well as use the advanced column filter. I also used the column formatter and applied some conditional styling to it. All good so far 😃

1reaction
AllenFangcommented, Sep 29, 2016

@tester5, sorry for lately reply,

Cause you leave one column in the BootstrapTable child, like your snippet,

<BootstrapTable data={products2} striped={true} hover={true} condensed={true} columnFilter={true} pagination={true} search={true}>
      <TableHeaderColumn dataField="id" isKey={true} dataAlign="left" width="70px" dataSort={true}>#</TableHeaderColumn><TableHeaderColumn dataField="carfilename" dataSort={true} width="300px">Car filename</TableHeaderColumn>
      {envColumns}            
</BootstrapTable>

you can fix it by following:

<BootstrapTable data={products2} striped={true} hover={true} condensed={true} columnFilter={true} pagination={true} search={true} keyField='id'>
      {envColumns}            
</BootstrapTable>

Thanks 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamically generated columns · Issue #450 - GitHub
Do you know of a way to dynamically generate columns? I have something like this in mind (inside the render method): const columns...
Read more >
Problems passing a dynamic link to the table - Stack Overflow
I'm using react-bootstrap-table here, but every other option is a good deal. I have a big problem inserting a Link to the table....
Read more >
React Bootstrap Table - Contributors - GitHub Pages
List all contributors for react-bootstrap-table. ... <BootstrapTable data={data} > <TableHeaderColumn dataField="name" ... Dynamic Select Row.
Read more >
[Solved]-How to do React-Table Dynamic Header?-Reactjs
How to customize React Antd table header with table data? ... How to get dynamic table header from an array in react? ......
Read more >
How To Create Dynamic Table In React JS #reactjs ... - YouTube
Consultation: learningcurvebook@gmail.comText only #: 740-764-6334 # react #reactjs #tutorial #coding #webdev #webdevelopment #programming In ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found