table icon indicating copy to clipboard operation
table copied to clipboard

show: false in column is still showing column

Open aprTaylor opened this issue 6 years ago • 41 comments

In Version 7:

Describe the bug Setting show to false in the column appears to have no effect

To Reproduce Steps to reproduce the behavior:

//In code useTable({columns: [{accessor: "uid", Header: "uid", show: false}], data})

Result: column uid is still visible.

Expected behavior The column with show: false to not be visible

Codesandbox! codesandbox

Screenshots image

Desktop (please complete the following information):

  • OS: Windows
  • Browser firefox
  • Version 71.0

Additional context

aprTaylor avatar Dec 23 '19 03:12 aprTaylor

Looking at the recently closed issues, I think show is deprecated and it's recommended to use the new initialState.hiddenColumns state.

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

thisizkp avatar Dec 24 '19 04:12 thisizkp

but this doesn't seem to hide the header for that respective column; How do I do that? 🤔

thisizkp avatar Dec 24 '19 07:12 thisizkp

@thisizkp Thanks for the info! In the codesandbox it seems to hide both the column and the header. This is from the basic example, I just added the initalState.

image

aprTaylor avatar Dec 24 '19 22:12 aprTaylor

@agray5 Great, that seems to be working fine then. I'm not sure what prevented the header from hiding in my case. Will check that out.

thisizkp avatar Dec 25 '19 06:12 thisizkp

I just want to add that from the DX point of view, using hiddenColumns can be not perfect. I've tried using it, it works, but I would really like to see something like isVisible on a column working as a default value for the column visibility.

Basically, column state > hiddenColumns > columns table option, from the more prioritized to the less. Alongside canBeToggledHidden or something like that this would make it possible to make the state from the definition persistent (basically, canBeToggledHidden flag would mean “take the state on the column definition be it hidden/shown and discard the current state, the hiddenColumns and do not show the controls for the toggling”, similar to other similar plugins).

kizu avatar Dec 26 '19 01:12 kizu

@agray5 Great, that seems to be working fine then. I'm not sure what prevented the header from hiding in my case. Will check that out.

@thisizkp I had the same issue. I was accessing the headers/columns directly from the useTable hook since I don't have any header grouping. This seems to return all columns and is not taking visibility into account. I eventually changed my implementation so that I always go through the headerGroup first like so: {headerGroups[0].headers.map(column => ( <MyColumnHeader {...column.getHeaderProps( column.getSortByToggleProps() )} > {column.render('Header')} </MyColumnHeader> ))}

bjaging avatar Jan 02 '20 13:01 bjaging

column.isVisible will work on a column (though I believe it is undocumented) and I'm pretty sure it will override any state to hide or unhide the column as well.

tannerlinsley avatar Jan 08 '20 23:01 tannerlinsley

@tannerlinsley tried isVisible: false but still not working. version 7.0.0-rc.15 can someone please give an example? Thanks

jackyq2015 avatar Jan 13 '20 00:01 jackyq2015

I am experiencing the same problem. I am using 7.0.0-rc.15 and isVisible is not working.

DaniloOliveira28 avatar Jan 13 '20 21:01 DaniloOliveira28

@tannerlinsley Is column.show supposed to be handled by developers using useTable - or is useTable supposed to filter out those columns for us?

aaryn101 avatar Jan 15 '20 19:01 aaryn101

If show is deprecated, maybe we should remove it from the Column options documentation ?

I'm willing to do it + document isVisible if it's the way it is intended to be 👍

mbeaudru avatar Jan 16 '20 15:01 mbeaudru

show is not so much deprecated as no longer there (there's no longer any code reference to it). Looking at the code, I think that the only way to adjust column visibility is to use the initialState.hiddenColumns option.

ggascoigne avatar Jan 28 '20 18:01 ggascoigne

show is not so much deprecated as no longer there (there's no longer any code reference to it). Looking at the code, I think that the only way to adjust column visibility is to use the initialState.hiddenColumns option.

show is still present in the documentation and I can't imagine that initialState.hiddenColumns is truly the replacement, so it seems like this functionality was either forgotten about, left for later, or expected to be implemented by whatever component calls useTable.

aaryn101 avatar Jan 28 '20 19:01 aaryn101

The docs have been updated. Thanks for your help everyone!

tannerlinsley avatar Feb 14 '20 20:02 tannerlinsley

Maybe we should have kept this in the documentation indicating it's deprecated. Older resources still contain show field and I've spent some time trying to figure out why show was not working.

And was not able to find initialState.hiddenColumns as it's under Table documentation and can't be searched by 'visible', 'show' or 'hide` keywords.

kuzdogan avatar Apr 08 '20 11:04 kuzdogan

isVisible, still not working, I have tried to update the simple table example.

When I tried to use console.log on the column where I set isVisible: false, I noticed that it was set to true, so I guess there is something that overriding the column's state. image

Do I need to do both isVisible: false and the initialState.hiddenColumns ?

malsioufi avatar Apr 20 '20 07:04 malsioufi

For typescript, both column.isVisible and column. show throws error as Property doesnt exsist on type Column, any possible fix for this? I am using types doc from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-table

at-webdev avatar Apr 21 '20 18:04 at-webdev

@malsioufi looking at the code, column.isVisible isn't an input parameter, it's a reflection of the calculated state based on examining the hiddenColumns.

@at-webdev column.isVisible is defined on UseTableColumnProps and is part of the ColumnInstance interface. Again, I suspect that you are trying to use it as an option on the initial columns, and it just doesn't work that way.

ggascoigne avatar Apr 21 '20 18:04 ggascoigne

@ggascoigne Thanks! It works on JS environment but not on Typescript environment. I have set isVisible on column definition, accessed column.isVisible on the below sandbox.

https://codesandbox.io/s/relaxed-night-y5gcl?file=/src/App.js.

I am wondering why it isnt working same way on typescript environment?

at-webdev avatar Apr 21 '20 20:04 at-webdev

So this isn't about how the library works so much as how typescript works.

you added:

React.useEffect(() => {
    setHiddenColumns(
      columns.filter(column => !column.isVisible).map(column => column.accessor)
    );
  }, [setHiddenColumns, columns]);

You are relying on adding an attribute to Column that you then process before setting the hidden column list. You could have called it foo and had the same behavior.

You've effectively added a new attribute to the column object, and it's one that isn't in the definition so you get an error.

If you want to modify the attributes of the Column definition then you can add them to the definition in react-table-config.d.ts.

ggascoigne avatar Apr 21 '20 20:04 ggascoigne