In this article I will demonstrate a method for hiding columns using CSS and making an XPages view Panel pseudo-responsive.
What is Responsive Design?
- Responsive design is an approach to web page creation that makes use of flexible layouts, flexible images and cascading style sheet media queries. The goal of responsive design is to build web pages that detect the visitor’s screen size and orientation and change the layout accordingly.
Introduction
XPages view panels out of the box are not “responsive”, in that they make no attempt to, and do not work well on a mobile device.
One solution demonstrated by Stewart Curry is to hide columns as the width of the browser decreases. Hiding the least significant, down to the most when the view space is smallest. This makes sense because you would not want to display 9 columns worth of data on a mobile device anyway.
Using the following CSS I was easily able to make an XPages view panel “work” at different resolutions by reducing the number of displayed columns. (IE9 and above http://caniuse.com/#search=nth-child)
<style> .xspDataTable {width: 75%} @media only screen and (max-width: 1000px) { .xspDataTable tr td:nth-child(2), .xspDataTable tr th:nth-child(2) { display:none; visibility:hidden; } } @media only screen and (max-width: 768px) { .xspDataTable tr td:nth-child(3), .xspDataTable tr th:nth-child(3) { display:none; visibility:hidden; } } @media only screen and (max-width: 480px) { .xspDataTable tr td:nth-child(1), .xspDataTable tr th:nth-child(1) { display:none; visibility:hidden; } } </style>
How does it work?
The CSS media queries (IE9 and above) determine the CSS displayed depending on the width of the page (1000px, 768px and 480px in this case). At each stage I remove one column until I am left with just the detail as you can see below.
At > 768px
At > 480px
and below 480px
Conclusion
This is not the only “method” for trying to achieve responsiveness out of tables, but definitely my favorite 🙂
I seriously like this little piece of code. Thanks for sharing!
Glad you like it mate 🙂
Very nice Mark, thank you for sharing.
Additionally, if you use Bootstrap and apply Bootstrap table style classes to your view panel, it will be rendered rather nicely looking, even on a mobile device