Giter Club home page Giter Club logo

Comments (2)

jasonphillips avatar jasonphillips commented on May 25, 2024 1

I think I can spot a problem up front after glancing at your code above; check this section where the error occurs:

<Thead>{headerGroups.map((h, i) => {
    <Tr>
      <Th>{i}</Th>
    </Tr>
  })
}</Thead>

Since you use { } around your map function, those contents (<Tr>...</Tr>) aren't actually getting returned. Second, I don't think you intend to create a row for each header, just a header cell for each within a single row. So you would need to change it up to something like this:

<Thead>
  <Tr>
    {headerGroups.map((h, i) => 
      <Th key={i}>{h}</Th>
    )}
  </Tr>
</Thead>

That way, the contents of your map function will be returned. I also added a key prop since that's preferable any time you have a map.

Now, as for making it work correctly with this library and dynamic headers, the thing you'll need to do is change another key prop on the main <Table> component whenever the columns would be changing--that change lets React know to recreate the component from scratch, which will ensure this library rebuilds the structure of the table headers.

You could do something simple like this, since your headers are just a list of strings inside headerGroups:

<Table
  key={headerGroups.join('|')}
  {...getTableProps()} 
  className='table table-striped table-hover'
>

That merely creates a string key out of the list of headers, so that it will change when they change. I just quickly typed out all of the above, however, so it might be missing something in your use case. If headerGroups doesn't contain strings but something else (I can't tell above), you would use a different method than a join--just any simple way to create a unique string out of the current headerGroups.

from react-super-responsive-table.

facing-n avatar facing-n commented on May 25, 2024 1

@jasonphillips Thank you very much - these insights helped me to resolve my issue - had been banging my head for a while.

from react-super-responsive-table.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.