Comments (2)
Good call; this is a consequence of a couple of things.
There's a PR now to update the internal use of context (which was on the old paradigm, that doesn't broadcast changes well) to use the new official Context API in React 16;
...but in this case, a glance back through the code reminded me that the real issue is how the headers have to be statefully stored on first render of the table, since the library doesn't use props for them and just checks the children of the thead
to build its internal list of headers upon construction.
The code could be updated to more smartly handle this situation of deriving state during initial render, but a simple workaround is to follow one of the latest "official" recommendations on this topic and just use a key
prop to ensure the components are all internally updated when you're making this kind of change.
I think that's reasonable for now, since a change in key
essentially indicates to React "this is now a new table, not merely new data inside the old one" and should solve your problem reasonably well when you're looking to dynamically change the columns.
I added a test related to this in the latest PR; look at it to see how I set a key
prop (just on the Table
element itself will suffice) and change it when the columns are changed.
It boils down to using something like this:
<Table key={i}>
<Thead>
<Tr>
<Th>{headers[0]}</Th>
<Th>{headers[1]}</Th>
</Tr>
</Thead>
<Tbody>
<Tr>
<Td>item 1</Td>
<Td>item 2</Td>
</Tr>
</Tbody>
</Table>
...so that if you ensure that the key
prop on the Table changes whenever the headers change, the table should update correctly and the new header context should make its way into all the cells, solving the mobile issue you noticed.
@coston - probably makes sense to add this to documentation under "using dynamic headers" or something
from react-super-responsive-table.
@lazev3do i've added a simple section to the readme with instructions taken from the comment above from @jasonphillips. How does this resolution work for you?
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.