Comments (2)
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.
@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)
- Action Required: Fix Renovate Configuration
- Headers disappearing when table pivots at breakpoint HOT 6
- Add css class for mobile view HOT 4
- THead not working with react-table hooks. HOT 4
- Prevent header column to repeate on every row HOT 3
- Cells without value dont create cell in target card, field value not on same row how field key HOT 4
- Error: Element type is invalid HOT 15
- Header in mobile view is not shown HOT 12
- Still having trouble with dynamic header HOT 2
- Request: Add support for React 18.x.x HOT 7
- How to customize CSS for the table and its elements?
- Change the width of headers in mobile view. HOT 6
- Styles do not get overriden
- Trying to use react beautiful dnd with superresponsive table but getting error while using ref inside <Tbody> and <Tr> HOT 2
- Can we use useTable hook with this table?
- replace defaultProps to default parameters HOT 6
- Header Height Responsiveness Issue HOT 1
- Place <td> below the <th> in mobile view instead of placing it on <th>'s right side. HOT 3
- Error : Global is not define. HOT 1
- React not recognising prop on a DOM element;
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-super-responsive-table.