2

I am trying to acheive a dynamicallly populated columns with data, using facebooks's fixed data table. I receive data with columns ranging from 10 - 100. So my intent was to create columns dynamically. Below is what I have tried

Class App extensd React.Component{
  render(){
    return (
            <Table
              rowHeight={50}
              headerHeight={30}
              groupHeaderHeight={30}
              rowsCount={10}
              width={tableWidth}
              height={500}
              {...this.props}>
              
            {["firstName","lastName","bs","email"].forEach(function(columnName){
            return <Column
                    columnKey={columnName}
                    header={ <Cell>Header</Cell>}
                    cell={<Cell>Cell Content</Cell>}
                    width={200}
  />
  )
    }
})}

It doesn't work. Has anyone tried anything like that before? Any help will be appreciated. Thank you in advance.

3
  • you have misspelled extends. Also the tags you open needs to be closed with closing tags if there are child components inside Commented Mar 28, 2016 at 13:20
  • 3
    In addition to the misspellings, the forEach method does not return a new array; you need to use map instead. Commented Mar 28, 2016 at 14:15
  • Thanks @JeffWooden. That was really dumb me. Commented Mar 28, 2016 at 17:45

1 Answer 1

4

What worked was, replacing forEach with map. Thanks @jeff-Wooden.

Class App extends React.Component{
  render(){
    return (
            <Table
              rowHeight={50}
              headerHeight={30}
              groupHeaderHeight={30}
              rowsCount={10}
              width={tableWidth}
              height={500}
              {...this.props}>
              
            {["firstName","lastName","bs","email"].map(function(columnName){
            return <Column
                    columnKey={columnName}
                    header={ <Cell>Header</Cell>}
                    cell={<Cell>Cell Content</Cell>}
                    width={200}
  />
  )
    }
})}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.