I created a view using "Table" as its format already. When I click on the title column record it shows the fields one by one.
Can I display the data of a view as table format?
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
The DataTables module might help to further enhance the prior answers to this question. Here is a quote from its project page:
The DataTables module integrates the jQuery plugin DataTables into Drupal as a views style and a callable theme function. DataTables lets you add dynamic features to tables, including:
- Variable length pagination
- On-the-fly filtering
- Sorting with data type detection
- Smart handling of column widths
- Themeable by CSS
- And more ...
Another feature that it offers is that you can "hide" specific columns from the default table display. But still the user has the option to do things like:
So you could use an approach to only show, by default, a subset of all the columns, and leave it to the user to yes/no also display the (initially hidden) columns.
A few more links you may want to look at:
Refer to the (short) video about Create Powerful Tables with the DataTables jQuery Plugin and Views for an intro about it, and how to use it as a views style plugin. Using the "settings" link for this views style, you can specify all sorts of dataTables options/features. In the above video starting from around 3:00 you see many of them.
Below is a screenprint of such display using DataTables. It's a display created using Views (of course) with a table with:
Here is how the DataTables display looks like:
For each row there is a link 'Show Details' (in its 1st column). If you click on one (or more) of them, the hidden fields of such row are shown below that row (with grey background here) and the link you clicked changes to 'Hide Details'. Obviously, I've not done any styling for such expanded row (hence the grey background, etc). But you can see the 3 fields that were initially hidden.
Bonus: assume none of the rows are shown expanded, and you type "
Basic" in the DataTables search box. It will then dynamically (in the browser, no server calls) reduce the table display to only those rows with
Basic Page as value for "Type". But wait, there is even more: if you'd type a string like part of "
21:15" instead (hidden in some of the rows), it will also dynamically reduce the table display to only those rows, like the expanded row shown in the screenprint. But wait, there is even (quite) a bit more: a search string like "basic 21:15" will filter the rows to a combination of both search strings. For only this one feature I often recommend the amazing DataTables module, one of Drupal's hidden gems I think. And then there are the other features like pager, sortable columns, etc.
Make sure to use the 1.9.x version of the DataTables library (not 1.10.x or above), as mentioned also on the project page, which states:
While there is work in the 7.x-2.x branch to upgrade to the latest DataTables version (1.10.x), the 7.x-1.x branch only works with DataTables <= 1.9.x. Since it's not listed in the projects download page, you will have to download it directly.
When creating a view, disable the pager of your view, since DataTables provides its own paging features (the video talks about that starting from 2:05).
In the Views interface, in "Format", you can select the "Table" format, instead of the default "Unformatted list".