HI,
Can you please let us know how to hide/show columns based on condition?
Thanks in advance!
Regards,
Sajjan Hubale
Conditional columns for Datatable
I was not able to find a native way to do this within the DataTable component.
However, it is easy to do with conditional CSS.
You'll want to initialize state within your component, and set it to true or false. For example, on my current project, I have a "debugMode" that shows or hides certain columns that end users do not need to see.
When your state "showHiddenColumns" is false, the CSS will be and will override the default style.
But when the boolean is true, the blank ' ' value will revert to the default style.
However, it is easy to do with conditional CSS.
You'll want to initialize state within your component, and set it to true or false. For example, on my current project, I have a "debugMode" that shows or hides certain columns that end users do not need to see.
Code: Select all
<Column field='ID' header='ID' style={{display: this.state.showHiddenColumns ? ' ' : 'none' }}/>
Code: Select all
"display: 'none'
But when the boolean is true, the blank ' ' value will revert to the default style.
-
- Posts: 5281
- Joined: 29 Jun 2013, 12:38
Hi,
Yes, you can add a custom style for this issue Or you can use dynamic column feature of datatable. Please see this demo; https://www.primefaces.org/primereact/#/datatable (the second demo)
Best Regards,
Yes, you can add a custom style for this issue Or you can use dynamic column feature of datatable. Please see this demo; https://www.primefaces.org/primereact/#/datatable (the second demo)
Best Regards,
Github Profile: https://github.com/mertsincan
-
- Information
-
Who is online
Users browsing this forum: No registered users and 22 guests