Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To Hide a Column #917

Closed
gmarathi-nisum-com opened this issue Sep 4, 2017 · 12 comments
Closed

To Hide a Column #917

gmarathi-nisum-com opened this issue Sep 4, 2017 · 12 comments

Comments

@gmarathi-nisum-com
Copy link

this.columns = [
{ key: 'Name', name: 'Name', filterable: true, sortable: true, resizable: true },
{ key: 'State', name: 'State', filterable: true, sortable: true, resizable: true },
{ key: 'Country', name: 'Country', filterable: true, sortable: true, resizable: true },
{ key: 'Id', name: 'Id', filterable: true, sortable: true, resizable: true }
];

My column header are above.
Is there any property to column header object where we can hide them on page.

@jpdriver
Copy link
Contributor

jpdriver commented Sep 5, 2017

hey @gmarathi-nisum-com -- you should be able to do this by passing hidden: true on a column object

@gmarathi-nisum-com
Copy link
Author

@jpdriver Thankyou for the reply. I tried it. But it is taking space of hidden column in table.

@martinnov92
Copy link
Contributor

martinnov92 commented Sep 5, 2017

Hello, I am doing it by settings my own property for columns to for examplevisible: true and then in render method I filter only those columns which are not hidden (const cols = this.columns.filter(column => column.visible === true)) and then I pass the cols array to the grid...

@gmarathi-nisum-com
Copy link
Author

@martinnov92 Thank you!!

@vnallamhawk
Copy link

hello @martinnov92 . In your snippet, when you implement it is still occupying space for the hidden column right?

@DhanaTontanahal
Copy link

You can have a column chooser whcih dynamically hides or shows the column when you check or uncheck the checkbox against the column name, just have a property like show(default true) or any property like visible and filtering the columns whose show or visible property has become false to be hidden else when checked they will be shown.

Here is the working example
https://github.com/DhanaTontanahal/reactdatagrid_hidecolumns_dynamically

@ogg130
Copy link

ogg130 commented Feb 10, 2020

Super High tech solution incoming!!!

  1. Give the column a value of hidden, which will hide the column but not the column header.

  2. Give the column an empty name or else you will see text in the header.

  3. Give the column a width of -1. A width of 0 leaves a small empty header column, but -1 'hides' it apparently. Not sure why it works, im not a css master, but it works.

const columnTemplate = [
{
{
key: "costCenter",
name: "",
width: -1,
hidden: true
}
}
];

@tonyabracadabra
Copy link

You can have a column chooser whcih dynamically hides or shows the column when you check or uncheck the checkbox against the column name, just have a property like show(default true) or any property like visible and filtering the columns whose show or visible property has become false to be hidden else when checked they will be shown.

Here is the working example
https://github.com/DhanaTontanahal/reactdatagrid_hidecolumns_dynamically

You can have a column chooser whcih dynamically hides or shows the column when you check or uncheck the checkbox against the column name, just have a property like show(default true) or any property like visible and filtering the columns whose show or visible property has become false to be hidden else when checked they will be shown.

Here is the working example
https://github.com/DhanaTontanahal/reactdatagrid_hidecolumns_dynamically

Hey there! The link you provided is not working, am I able to hide a column on the fly without having to rerender the whole grid with your approach? Thanks a lot!

@ojnc ojnc mentioned this issue Mar 15, 2021
@ojnc
Copy link

ojnc commented Mar 15, 2021

This is a working demo of column choosing using checkboxes

https://drive.google.com/file/d/13esqen5Df_Hv8qT9nZWhpOTG3XZaWUuy/view?usp=sharing

Thanks to @martinnov92
And my idea of using row selection in a devious way

Dhana Shekhar Tontanahal well kept secret no longer needed!

@DhanaTontanahal
Copy link

DhanaTontanahal commented Mar 15, 2021 via email

@ojnc
Copy link

ojnc commented Mar 15, 2021

Hi Dhana
This is all about react-data-grid
Your example has nothing to do with react-data-grid
It may be very good but this repository is https://github.com/adazzle/react-data-grid

Your package.json has no trace of react-data-grid
Your solution is for "react-table": "^6.8.6",

My code is 100% vanilla react-data-grid

Regards
Jayanta

@stephentan
Copy link

stephentan commented Sep 10, 2024

Super High tech solution incoming!!!

  1. Give the column a value of hidden, which will hide the column but not the column header.
  2. Give the column an empty name or else you will see text in the header.
  3. Give the column a width of -1. A width of 0 leaves a small empty header column, but -1 'hides' it apparently. Not sure why it works, im not a css master, but it works.

const columnTemplate = [ { { key: "costCenter", name: "", width: -1, hidden: true } } ];

Thanks ogg130
This worked for me! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants