Views (Table Format) - how to show ONLY those fields that have been filtered as opposed to all fields?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
spessex's picture

I have a view showing a table with say about 20 fields attached to it and exposed filters for all these fields. My question is assuming I am only filtering on 5 fields how can I ensure the table only shows these 5 fields that I have filtered as opposed to bringing back the results but still showing all the other fields as well?

To be clear imagine I have 'User', 'Age', 'DOB', 'Location', 'Gender' as fields and as exposed filters. If I only filter on 'User' and 'Age' I only want the results to show those two field columns (User and Age) not all the fields columns like it would do now in the table.

I've searched everywhere but am having no luck on how to do this and I would imagine this should be feasible.

Any help would be much appreciated.

Stephen

Comments

Look at the Views generated SQL

__ian's picture

Hi Stephen,

Have a look at the SQL generated by Views when you preview it. You'll see a list of fields between the SELECT and the FROM clauses.

Only the 2 fields that you're displaying should appear, not others, unless you've added them but excluded them from appearing.

Ian.

Might need custom code

khaled.zaidan's picture

I've never seen any contrib module do this.

What I would do is add classes to the view wrapper depending on the filters set in the URL. I would hide all the fields in the view be default (simple "display: none"). And using the classes I added, I would "display: block" the fields used.

Off the tip of my head (never actually done this) maybe in the preprocess of the view tpl file, I'd add the classes. There you can check the $view object, and I'm sure you can figure out the classes to be added depending on the data in the object.

This obviously needs some custom coding. But if more people find this interesting, it might be worth it to give it some thought and make into a contrib module (where you wouldn't need to write any custom code)

I hope I helped!

Khaled Z.

Views Table Manager

Steven Jones's picture

So a possible line of a solution could be found from this sandbox module: http://drupal.org/sandbox/drob1nson/1168518 which is discussed in this thread: http://drupal.org/node/1169006

Sadly it seems that this sandbox has been abandoned, and is only for Drupal 6, so you might have to 'convince' someone to port and bug fix it for you.

It appears I may have found

spessex's picture

It appears I may have found the solution using http://drupal.org/project/views_dependent_filters. It allows you to set a Global filter so once you have filted your criteria you can then apply the Global filter to ensure only the fileds you want to see are displayed.

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: