4

I have an ajax exposed filter in the views. When user select option from filter it loads content. But when I click on item on view and press browser back button, exposed filter resets and default option is selected. Same thing happen when I refresh the page.

Is there any way in view to preserve the last selected option? Same thing happens when I click on page number of views.

Thank you.

3 Answers 3

2

You'll have to turn off ajax to get this to work until this issue is resolved. See http://drupal.org/node/1248332

Then edit your exposed filter(s) and check off "Remember last selection".

3
  • Is there any work around so that I can have ajax also.
    – cissharp
    Jan 15, 2013 at 15:19
  • Not until that issue I mentioned above is fixed. You can help it along by offering to test. Jan 15, 2013 at 23:58
  • Can this be done with some module so user can press "back" button or something similar on website, so he does not have to use browsers back button.
    – Azz Kawa
    Sep 26, 2015 at 16:27
1

Thank you user2890. For anyone who comes across this, here is my improved version of user2890's code:

$('.views-exposed-widget select').each(function() {
    if (
        $(this).find(':selected').val() !==
        $(this).find('option[selected="selected"]').val()
    )
        $(this).trigger('change');
});

So this code would trigger 'change' event only if the selected option in the UI is different from the the option with selected="selected" attribute in HTML. As user2890 mentioned, you can put this code in $(document).ready().

0

A better solution is to use some Javascript. If you're using AJAX, you're already reliant on it. Here's a one liner, using jQuery.

    if($('.views-exposed-widget select').length) {
        $('.views-exposed-widget select').trigger('change');
    }

That goes in a normal document.ready brace. It will fire a change event on the select element, thereby triggering it's AJAX event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.