Currently we don't track the state of AJAX views. Users trigger reloads, but no state information is logged. Specifically, it is not possible for users to return to a particular state, short of repeating the steps to get there (e.g., load page, click a particular pager link).

Ideally we'd have full browser history support, but that's difficult given the state of jQuery history plugins (sketchy).

An interim approximation would be:

* set a URL fragment when loading by AJAX
* on initial page load, look for a fragment and, finding one, load it.

Issue fork drupal-343535

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

the problem is that the browser NEVER sends the fragment to the server

nedjo’s picture

We would need to parse and send the fragment via javascript on page load.

A good place to look for ideas is the new Asynchronous module, http://drupal.org/project/asynchronous, which used a jQuery history plugin.

Dave.Ingram’s picture

Title: Enable bookmarking of AJAX views » Sounds too unstable
Category: task » feature

The asynchronous module states:

This module requires Page renderer module and a theme that support dynamic loading (e.g. Chrysalis).

Both Asynchronous and Page renderer are dev versions, so this probably isn't a very stable thing to be trying to build into Views any time soon. I think it's great that people are making strides to make Ajax calls bookmarkable... but if it's not stable anywhere else yet, then there's no way it's going to get into Views.

Dave.Ingram’s picture

Title: Sounds too unstable » Enable bookmarking of AJAX views

Oops, didn't mean to change the title. Changed it back.

merlinofchaos’s picture

I don't think we need to use any kind of a plugin for this. All we need to do is have the browser check the fragment and make an ajax call if it exists; and to have the browser UPDATE the fragment on subsequent ajax calls.

Perhaps 'all' is understating how much work this actually is.

momper’s picture

subscribe

peterjmag’s picture

I realize that this issue is quite old now; is there another issue where this functionality is being discussed or worked on? If so, I'd be happy to test patches.

merlinofchaos’s picture

To my knowledge nobody is actually working on this. This would be a useful feature, though, and I'd support work on it.

Mohammed J. Razem’s picture

Priority: Normal » Critical

subscribing!

merlinofchaos’s picture

Priority: Critical » Normal

Wow, critical? Why does everyone think their needs are critical?

Mohammed J. Razem’s picture

Just to get attention for the importance of it! It might not be critical! But still it's important!

Mohammed J. Razem’s picture

And the issue is alive again since November 2009! That's the effect of Critical issues!

merlinofchaos’s picture

It's only alive if someone agrees to work on it. Maybe you should lobby dereine =)

thaddeusmt’s picture

it would be REALLY super if the AJAXed View remembered what view-page it was on when a link was clicked, and returned to that view-page again after the whole website-page reloaded.

it's a pain right now: if the user pages over six times in a sidebar view and clicks on a link, when the page reloads they have to page over six times again to click on the next link.

I can't find any views jQuery pagers/carousels that quite do what I want, either...

Drupal is so great most of the time I'm like "w00t! someone already did this I don't have to code it!" but then when I need to change/extend some of the functionality (like this) the awful reality of "someone else coded this now I have to unravel their strange, mysterious code before I have the faintest idea where to BEGIN to fix my problem" hits... :P

benone’s picture

SUBSCRIBE

url should be ALWAYS different for every different part of Drupal website.

merlinofchaos’s picture

url should be ALWAYS different for every different part of Drupal website.

With AJAX this just isn't always possible, so this is a basically useless statement to make.

benone’s picture

But without dynamic urls Ajax option for Views will be useless very soon also.

Golden rule is that every single click on the website should have unique url.

Or I read wrong tech blogs ?

merlinofchaos’s picture

No offense, but if it's that important to you, please help with the feature request. Your posts are coming off like orders.

benone’s picture

Don't read me in a wrong way, I have only good intentions. I am views fan and views are fun for me. :)
Just read some articles and this one often appears - unique urls.
I never carried about that before when I was using ajax in views but now I just start understand how important it is.
So I wrote about that.

If I knew more about ajax I would upload some example patch here for sure.
Also would do this for jCarouselLite module which works crossly-browser perfect as views blocks. But the same - URL always the same.
I wrote about it here: http://drupal.org/node/762956

Believe me I thought its not a big change, just something in javascript which changes current url in a browser after each click.

Now I realize its not so easy to achieve that.

merlinofchaos’s picture

My experience is that with AJAX, it varies depending on how you are using it. Traditionally most AJAX in Drupal has been for form manipulation, and you don't want unique URLs for that. When using AJAX on pagers, indeed unique URLs are something you want. However, it's not as easy as all that because it means that you need to interpret the fragments as soon as the page loads and perform the proper ajax. That makes it hard to just add generically. I'm not saying it's impossible, but it's not a simple problem to solve, which is why no one has yet taken the time to solve it for Views.

benone’s picture

I thought adding onClick='javascript:change url...' would be enough.
But you say it must be done after page load. So I believe you are right and have nothing more to add. :)

merlinofchaos’s picture

You are not allowed to change the actual URL with javascript, only the fragment. That's why it's so hard.

benone’s picture

Which fragment ?

And is possible not to change , just add '?p=2' in the end ?

merlinofchaos’s picture

No, only the fragment, which is the part after the #

scott859’s picture

subscribing

JordanMagnuson’s picture

Subscribing. Would it be possible, as an in-between step, to allow ajax views results to be bookmarked via clicking on a link, ala the "[link]" feature at http://drupalmodules.com/ ?

merlinofchaos’s picture

Yes, this should certainly be possible; the pagers are able to retain exposed filters, and that makes total sense as an option to AJAX exposed filters. Patches will definitely be considered.

iamjon’s picture

Category: feature » task

I'm marked this as an unassigned task. If anyone would like to role up their sleeves and take it upon themselves to write a patch it would be awesome

denny84’s picture

Can anyone think about "%menu_tail" ?

tim.plunkett’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev

I've used the jQuery BBQ hashchange plugin for things similar to this, and that plugin is now included in D7, but it's used for the Overlay, so I'm not sure that we can reuse it for Views.

merlinofchaos’s picture

We possibly can but it's going to create some ugly URLs. The real issue is going to arise that you can have repeated ajax operations that move you quite a ways through a set of views. Plus, there is a LOT of data that goes into ajaxing a view and it all needs to be somewhere on the page. One of the reasons I've never tackled this is that I'm afraid of how much the data can balloon leading to enormous URLs.

brunorios1’s picture

subscribing

nod_’s picture

Hi guys, I have a sandbox project that deals with this. I'm not making a patch here because it needs an external lib. and I'm not sure how much it'll be possible to integrate. It's missing ui options and all that for now.

I haven't put it through rigorous testing yet, still, it works for basic exposed filters and pager. Here is the tentative module name : views_ajax_history.

The amount of data is actually not that bad (or I missed some pretty huge stuff) as far as state saving goes, it's all done by the browser and the length of URL is not bigger than a view without ajax enabled.

idflood’s picture

@nod_: nice :) I haven't tested it but if I'm right the external library you are mentioning is history.js. I believe you can use the integrated jQuery BBQ instead. It would remove the external library issue.

nod_’s picture

Might not be the place to discuss this, but history.js is actually much better statechange > hashchange. You don't need the # anymore on proper browsers.

A lot of time passed since #22 :)

tim.plunkett’s picture

@nod_ yes, but bbq is included in core, which makes it that much easier to use, and even adds a possibility of it being included in Views...

nod_’s picture

hash urls are fine for admin pages, I'd be very sad to see that on views pages. Using a hash has his own sets of issues too, the intelligent state handling page from history.js has a pretty good writeup which I share.

As usual IE is the problem, everything is fine for other browsers. If you absolutely need history I'd say just don't use ajax views. If this goes in views somehow I really don't think it should be on by default either (except for a clean implementation using statechange).

In any case I really don't want to contribute to views by introducing the crazy url hash hack just because it's used by core.

nod_’s picture

Who cares about my opinion anyway, it's important and I just have to make the thing pluggable to allow for a different library to be used by contrib. If someone can walk me trough the best way to do that in views (a new class? just some JS wizardry?) that'd be nice.

If someone wants to help the js part is here : views_ajax_history.js. There is no config form for this either, *wink* *wink*.

Anyway I'll get working on a patch using bbq to include that in views.

nod_’s picture

Sorry, no patch yet, just adding a reference to #1341226: Discuss the use of the History API in the overlay module.

geerlingguy’s picture

See also: #1084336: Use HTML5 History API for AJAX (so URL preserves state of exposed filters) - perhaps that issue should be marked duplicate?

mkadin’s picture

In the interim is it at all possible to allow for the ajax to still function even if there is a &page=X in the query string? For example, I've got some links to specific pages of a view that uses ajax...but if I go to myview&page=3, the ajax pager no longer functions. Throbber shows up, goes away, page stays the same. It seems as though we could still get that to work, even without fancy javascript stuff. And that would get us part of the way towards bookmarking specific pages in an ajax-paged view.

Is this a separate bug that deserves its own issue?

I'd be happy to work on it if someone can point me in the right direction...I'm having trouble finding the right place in the code for this...

matt2000’s picture

I can't believe I missed this thread while searching for existing issues. I've implemented a solution in a patch to Views 3.5 here:

#1786904: Deep link filter settings & Reload results from AJAX submit when using the browser's back button

attila.fekete’s picture

I would suggest https://drupal.org/project/views_ajax_history by nod_. It's not a sandbox project anymore, and works great.

herd45’s picture

This module allows users to save ajax views. Each saved view is an entity.

https://drupal.org/project/views_save

AaronBauman’s picture

Issue summary: View changes

Any chance of getting this into views core?
This is standard / expected behavior for modern web apps.

candelas’s picture

I don't know enough about Views coding, but maybe you are interested in this solution that I found
http://www.accessadvertising.co.uk/blog/2013/03/html5-history-api-ajax-u...
http://www.accessadvertising.co.uk/blog/2013/04/html5-history-api-making... (here the solution)

Thanks for so much shared code :)

AaronMcHale’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 7.x-3.x-dev » 8.8.x-dev
Component: Code » views_ui.module

I came accross this today when experimenting with using AJAX option for Views, I was hoping that the URL would be updated when filters and pagination changes (like it does without AJAX enabled), maybe this issue could be restarted?

marcvangend’s picture

Re #47: Did you try the module mentioned in comment #43? If so, I'd like to know if it worked for you.

AaronMcHale’s picture

Re #48 thanks for linking that, haven't tried that yet

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pivica’s picture

> Re #47: Did you try the module mentioned in comment #43? If so, I'd like to know if it worked for you.

For anybody interested for this I can verify that https://drupal.org/project/views_ajax_history works fine for both filters and pager on Drupal 8 site. Will report if i find any problems, but for now it seems this module is a good solution until core supports this in the future.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

claudiu.cristea made their first commit to this issue’s fork.

claudiu.cristea’s picture

Status: Active » Needs review
claudiu.cristea’s picture

Issue tags: +Needs tests

For sure needs test coverage.

claudiu.cristea’s picture

Title: Enable bookmarking of AJAX views » 343535-ajax
Issue tags: -Needs tests

Tests provided.

claudiu.cristea’s picture

I'm not sure we have to add also the pager info in URL

claudiu.cristea’s picture

Title: 343535-ajax » Enable bookmarking of AJAX views
claudiu.cristea’s picture

Issue tags: +JavaScript
claudiu.cristea’s picture

Component: views_ui.module » views.module
Category: Task » Feature request

This looks like a Feature request and belongs more to Views rather than Views UI.

I see the pager is added correctly. Other question is whether we want to clean the URL for filters that are showing default values, making the whole URL (which, being displayed in the browser's address bar, is somehow part of the UI) much more cleaner.

matthiasm11’s picture

The patch from #59 will change the url in the address bar incorrectly when the view is a block instead of a page.
When the view is a block, the view_base_path is empty.

Example: a node /node/1 with alias /categories-overview containing a views block "categories" with filter "color". After changing the color filter, the url would be mysite.com/?color=red instead of mysite.com/categories-overview?color=red.

The attached patch fixes this, so the url will be mysite.com/categories-overview?color=red.

Status: Needs review » Needs work

The last submitted patch, 65: enable_bookmarking_of_ajax_view-343535-65.patch, failed testing. View results

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

prudloff’s picture

Here is a reroll for Drupal 10.0.

ameymudras’s picture

Status: Needs work » Needs review
FileSize
9.2 KB
1.16 KB
needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
2.46 KB

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

pooja saraah’s picture

Status: Needs work » Needs review
FileSize
9.2 KB
1.16 KB

Fixed failed commands on #70
Attached patch against Drupal 10.1.x

Status: Needs review » Needs work

The last submitted patch, 72: 343535-72.patch, failed testing. View results

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

webdrips’s picture

kachinsky’s picture

Hi @webdrips
Your patch doesn't work, the view returns the error after applying:
Error: Class "Drupal\views\Ajax\SetBrowserUrl" not found in Drupal\views\Controller\ViewAjaxController->ajaxView() (line 219 of /code/web/core/modules/views/src/Controller/ViewAjaxController.php)

shabana.navas’s picture

Is there a quick way we can clean up the URL that is built? Right now, I only have a couple of exposed filters and the URL already looks like this: ?date%5Bmin%5D%5Bdate%5D=2023-05-29&date%5Bmax%5D%5Bdate%5D=2023-06-16&promotion_type%5B6%5D=6&promotion_type%5B1%5D=1

prudloff’s picture

FileSize
9.29 KB

#72 does not apply to 10.1.0. Here is a reroll.

(I tried to generate an interdiff but it fails for some reason.)

elaman’s picture

FileSize
9.06 KB

The most recent patch causes a bug if user visits bookmarked url and tries to uncheck the existing filter. The main reason is that queryString is preserved when performing request to the ajax callback page:

    this.element_settings = {
      url: ajaxPath + queryString,
      submit: settings,
      httpMethod: 'GET',
      setClick: true,
      event: 'click',
      selector,
      progress: { type: 'fullscreen' },
    };

So you can't really reset bookmarked filters.

Also it is better to push new filter state into history, so you can use browser navigation to restore previous filter state.

elaman’s picture

FileSize
9.97 KB
elaman’s picture

FileSize
10.04 KB
elaman’s picture

FileSize
10.9 KB

Instead of removing queryString that caused issues, now remove only params that represent exposed filters.

prudloff’s picture

FileSize
10.92 KB

#82 causes a problem with pagination, for example :

  1. Check a filter that returns 3 page of results.
  2. Browse to page 3.
  3. Check another filter that only has one page of results.
  4. The view stays on page 3 and displays no result.

Remove the page param from the query string seems to fix it.

elaman’s picture

FileSize
10.97 KB
prudloff’s picture

FileSize
10.94 KB
1.54 KB

Here is a reroll of #83 for Drupal 10.2.

sakthi_dev made their first commit to this issue’s fork.

sakthi_dev changed the visibility of the branch 10.0.x to hidden.

sakthi_dev’s picture

Re rolled with 11.x.

GaëlG made their first commit to this issue’s fork.

GaëlG’s picture

Issue tags: +Needs tests

I made a fix so that browser URL is not updated if the view is in a dialog/modal, because in that case the browser URL is not the URL containing the view parameters.
It's like there's an URL for the page which is behind the modal (the one shown in the browser URL field), and one other URL ("hidden") for the "page" shown in the modal.
Without this fix, we got a strange behavior when using media library search in modal: it works the first time, but as soon as params are added to the browser URL, subsequent search is buggy until the whole page is reloaded.
I guess a test should be added for the modal case? Like just test that browser URL is not updated when an AJAX exposed form is used inside a modal.

And automated tests do not pass, I guess it's just some test code that needs to be updated for compatibility with current 11.x.

Then, I believe the merge request will be ready for review again.