Common Exposed filter for each tab in drupal 7

306 Views Asked by At

I have different fields and showing in different blocks, and want to apply exposed filter to all but my problem is it shows different exposed filters for each different block. I want to make it common for each block.

Below are the steps,

  1. I made 5 blocks to be displayed for each buttons.
  2. Added exposed filter for languages for each block.

Now each block showing its different exposed filter. But I want the exposed filter should be shown above the buttons and should work for each block display. Attached screenshot for the issue.

enter image description here

I installed Views Global Filter but is gives Session error.

2

There are 2 best solutions below

0
DeveloperWeeks On

I was just about to suggest the Views Global Filter.

Another way is to set a contextual filter on all your blocks that pulls from the url, so they each pull the same value. This is an active issue in the views issue queue, with a few people who have made it work: https://www.drupal.org/node/1587894 Comment #6 has some simple code, and that would be applied here https://www.drupal.org/node/1871388

0
Rohan Kumar On

After 3 days, I haven't found the solution, even by programmatically.

Then what I had the last option(in my mind, huh) is,

  1. I get all the fields in one block only, not creating the different blocks for different tab or buttons.
  2. Used the description of Better Exposed Filters, in which I pasted my buttons/tab UI HTML as its.
  3. Now on changing the language all the fields are fetched according to the selected language. But in this case my active tab/button get lost its activeness.
  4. Now, I need to get the last active tab/buuton, so that I can click it again to get the active tab after filtering my languages.

Below is the piece of code which is need to my js file.

// Active target element to make the tab/button active after 
// ajax responds in filter
var activeTargetElement;
Drupal.behaviors.events = {
    attach: function (context, settings) {
        $('#views-exposed-form-MY_VIEW_MACHINE_NAME-BLOCK_NAME', context).ajaxStart(function () {
            // my tabs/button are active on the basis of data-target attribute,
            // so need to memorise which tab/button is active before fitering any language 
            activeTargetElement = $('#MY_TABS li.active a').data('target');
        }).ajaxSuccess(function () {
            // if any target is memorised, then simply click it or trigger a click event for it
            if($('[data-target="'+activeTargetElement+'"]').length){
                $('[data-target="'+activeTargetElement+'"]').click();
            }
        });
    }
};