I have a view that returns a 4 column grid view. The client wants to be able to toggle between grid results and teaser results by clicking on an icon.
Does Views handle this naturally? Do I need to utilize AJAX?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
This Views mode module should be able to do this, however it is still in development version. Make sure to test it out on a development site before using it on a production site
A Drupal Views display plugin which provides alternate display modes that can be switched to for a single View. This allows exposed filter parameters or contextual filters to be kept active while switching display mode.
If you want to do something like this,
then you can use QuickTabs Module
So, here user can switch from TAB-ONE to TAB-TWO .. so on ..
To implement this, first you have to create View-Blocks and then you have to create Quick Tabs by using QuickTabs Module
Here is one Video Tutorial to create QuickTabs.
You can also create two views, one displays as a list and the other display as a grid. Each has its own url. As an example: View a list and a grid of music artist: 1 list view of artists, display as list, url=/music/artist&display=list 2 grid view of artists, displays as grid, url=/music/artist&display=grid
on both pages, create a header, Global: text area: and enter something like:
<a href="/music/artists&display=list" title="Show as list"><i class="fa fa-list"></i></a> <a href="/music/artists&display=grid" title="Show as grid"><i class="fa fa-th"></i></a>
PS i use fontawesome for icons.
This way you can have two pages, same content present in its own way, using a switch on top of both pages. Easy!
Studio Orange's answer is a good lightweight solution, though I'd like to add a couple of points to improve upon it (cannot post comments yet).
To make the view retain filters and page number while switching displays, you need some PHP and as using the PHP filter in the text area of the view is not too good of a practice, it's preferable to attach a header programmatically by implementing hook_views_pre_view().
For the link to retain page and filter values you will have to use the l() function along with drupal_get_query_parameters().
Take a look at the blog post I wrote for more details.