React-table: column show unwork

Created on 27 Nov 2019  路  7Comments  路  Source: tannerlinsley/react-table

Most helpful comment

As @hanvyj stated above, your renderer must use headerGroups, which are intended for display. headers is a flat list, provided as a utility for the exact reasons @hanvyj stated above as well.

All 7 comments

Workaround for now, you can filter the columns before rendering them:

{headers.filter(column => column.show).map(column => (
     <th {...column.getHeaderProps()}>{column.render("Header")}</th>
))}

Also, after having implemented hidden columns I think this is by design.

For the layout, I think you should use headerGroups:

      {headerGroups.map(headerGroup => (
          <tr {...headerGroup.getHeaderGroupProps()}>
            {headerGroup.headers.map(column => (
              <th {...column.getHeaderProps()}>{column.render('Header')}</th>
            ))}
          </tr>
        ))}

https://codesandbox.io/s/tannerlinsleyreact-table-basic-xr22d

This will hide columns without 'show' and should be used for rendering the columns.

Having access to the all headers is actually really useful if you want to, say, show a list of columns with checkboxes to show them etc.

I'm not sure what's going on here. Can you give me more information? The codesandbox definitely helps, but some more description of what is happening, what you're doing, and what you expect would greatly help.

As @hanvyj stated above, your renderer must use headerGroups, which are intended for display. headers is a flat list, provided as a utility for the exact reasons @hanvyj stated above as well.

I can make this "show" per column work in beta 26, not in 27 or 28. And none of the RC.
Is it by design? We shouldn't use column.show anymore?

It's recommended to use the new initialState.hiddenColumns state.

https://github.com/tannerlinsley/react-table/blob/master/docs/api/useTable.md#usetable

It's recommended to use the new initialState.hiddenColumns state.

https://github.com/tannerlinsley/react-table/blob/master/docs/api/useTable.md#usetable

So is column.show deprecated? Its not working in version 7.0.0-rc.15. initialState.hiddenColumns works, but column.show is more handy.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Oskii2311 picture Oskii2311  路  46Comments

Grsmto picture Grsmto  路  100Comments

hassankhan picture hassankhan  路  51Comments

ggascoigne picture ggascoigne  路  18Comments

vaidsu picture vaidsu  路  29Comments