Hello! I'm using igxGrid in a responsive app and would like to hide or show certain columns based on screen width. For example, on mobile, I want to hide less important columns to keep things clean.
igxGrid
Is there a recommended approach for responsive column visibility? Should I use media queries or listen to screen size changes in TypeScript?
Thanks for the suggestions!
Hello,
Thanks for your question regarding responsive behavior in igxGrid.
After exploring the best approach, I’ve implemented a solution that dynamically hides or shows columns based on screen width. Rather than relying on media queries in CSS, I’m using Angular’s BreakpointObserver from @angular/cdk/layout. This gives us better control and flexibility directly in the TypeScript code, and works perfectly with Ignite UI’s built-in column visibility feature.
Here’s how I’ve addressed it:
this.breakpointObserver.observe(['(max-width: 599px)']) .subscribe(result => this.isSmallScreen = result.matches); this.breakpointObserver.observe(['(max-width: 959px)']) .subscribe(result => this.isMediumOrLess = result.matches);
For example:
<igx-column field="City" [hidden]="isSmallScreen"></igx-column> <igx-column field="Country" [hidden]="isMediumOrLess"></igx-column>
The great part is that the grid automatically respects the visibility state. It also works seamlessly with the grid toolbar's column hiding UI, so users can still manage column visibility manually if needed.
You can view and test the working demo here: StackBlitz Demo
Please do not hesitate to contact me if you need any further assistance with this matter.
Regards,
Georgi Anastasov
Associate Software Developer
Infragistics