Are there problems with writing a pager in AJAX, or it's important for me? :)

Comments

Frando’s picture

Write it.
If it's well written, falling back cleanly with no javascript, and something that can be disabled, then I'm sure it will be considered.

alippai’s picture

Sorry...
Are there problems with writing a pager in AJAX, or it's important only for me? :)

RobRoy’s picture

I'd be very interested in an AJAX pager and think it would be a great addition to the jstools module. I could possibly help with some of the development as well, keep me posted.

Crell’s picture

There are several existing jQuery-based "infinite scroll" plugins. I would be very much in favor of a module that made it possible to drop-in one of those and have all table pagers become infinite scroll instead.

alippai’s picture

http://drupal.org/node/145551
IMHO this must be done, before anybody starts working on it :)

nedjo’s picture

For ideas, see the implementation in dynamicload.js in the dynamicload module, part of Javascript Tools. Specifically, pagers can be made to load dynamically by calling the method Drupal.dynamicloadPager.

The main limitation of the approach in dynamicload is that it assumes there is a single pager on a page and that loaded content should replace the current content of the main content area. This is appropriate in some cases, but in others will lead to broken results, e.g., when a pager is part of a panel's content and the expected result is that only that panel's content is replaced.

dropcube’s picture

Version: 6.x-dev » 7.x-dev
nedjo’s picture

Assigned: Unassigned » nedjo
Status: Active » Needs review
StatusFileSize
new8.93 KB
new2.14 KB

Here's a patch that introduces AJAX paging with an initial implementation for comments. The throbber-active.gif file goes in misc/.

Approach is:
* wrap paged output in a div that includes an ID for the pager data
* js attaches to link elements in pager div
* AJAX call passes pager data ID
* Rendering tests for this ID in the request and, if set, returns JSON

moshe weitzman’s picture

nitfty - subscribe.

Babalu’s picture

works this files with D6 too ?

Anonymous’s picture

bookmark.

nedjo’s picture

StatusFileSize
new2.14 KB
new8.04 KB

@Babalu: Nope, D7 only.

Here's a refinement. A problem with the previous patch version was that it explicitly called exit() to terminate the request. This version introduces a new menu constant, MENU_OUTPUT_COMPLETE, that can be returned to indicate that rendering is complete. This constant is returned from comment_render() if rendering was done in JSON. node_show() tests for this return value and, if found, returns the menu item request without further rendering.

In the previous patch I tried to reuse the Drupal.collapseScrollIntoView method to scroll to the newly loaded pager content but it didn't work. Removed here.

chx’s picture

Status: Needs review » Needs work

Well, already you can omit return (or explicitly return NULL) to omit the theme page call. if ($comments == MENU_OUTPUT_COMPLETE) feels like a tremendous hack to me. How can comments be a menu constant...

nedjo’s picture

StatusFileSize
new6.91 KB

@chx: good point. Reroll returning NULL.

nedjo’s picture

Status: Needs work » Needs review
nedjo’s picture

StatusFileSize
new7.67 KB

Adding back scrolling through a simple Drupal.scrollTo() method to scroll the window to the specified element. This should make for better usability--user is scrolled to the new items (in this case, comments) when they arrive.

nedjo’s picture

See this blog post for more detail on the approaches in this patch: http://www.civicactions.com/blog/AJAX_pagers_Drupal_7

Crell’s picture

Doesn't Views 2 implement an Ajax pager? Can't we build off of that?

nedjo’s picture

Good question. Some explanation:

This patch indeed draws on the one I did for Views 2, but with one important difference. Views 2 exposes a separate callback for AJAX requests, while this patch uses a single callback for both AJAX and non-AJAX requests.

We took that direction in Views for several reasons: 1. views needs to enable AJAX previews, which were already coded for; 2. views may need to be loaded at other than the regular page path (e.g., when views are on a block); 3. the same AJAX loading was needed for multiple purposes--pagers, exposed filters, and more.

So, while drawing on the previous work for Views, I don't think those reasons apply here, and I think it's cleanest to use a single callback rather than introducing a new one custom each time we need AJAX.

starbow’s picture

I feel mixed. This patch feels pretty limited, but the attempts to provide a more general solution are all bogged down, so maybe limited is the right approach.

nedjo’s picture

I see this patch as a concrete step toward just those general issues. Sometimes it helps to see the general through the specific.

We have two basic options when implementing AJAX fetching of JSON. One is to provide special callbacks for the AJAX request. That's what I'm trying to avoid in this patch.

The other is to provide a way to use the regular callback to retrieve the specific content requested. Since any number of possible requests could be made at a given path, it's not enough to be able to request "JSON". Rather, we need to make a request like "give me the comment pager results for this node matching these parameters".

For this, I think we need all of the elements in this patch.

Some review of the patch itself would be great. What if anything is missing? How well does this move forward the general problem of enabling more flexible content requests? If there are specific issues with the patch, what are they? How could they be addressed?

Anonymous’s picture

Status: Needs review » Needs work

The last submitted patch failed testing.

quicksketch’s picture

I'd like to give this a review. Although it might just be more work than it needs to be, the ahah.js file has the ability to work on things other than forms (like the pager links) if the necessary Drupal.settings are added manually. While code reuse is great, at the same time it's nice to have things self contained in JavaScript, especially since we don't yet have JS testing suites.

Gurpartap Singh’s picture

sun’s picture

Issue tags: +JavaScript

I wonder how much more of Views' functionality we want to duplicate instead of working on Views-in-core.

v8powerage’s picture

Are there no chances whatsoever to put this into 6.x?

catch’s picture

None in core whatsoever. But Views has a very nice ajax pager in contrib, on which this is based anyway.

v8powerage’s picture

Is this possible that using Views I could implement this ajax pager into topics at forum?

sun’s picture

Version: 7.x-dev » 8.x-dev

Status: Needs work » Needs review

paolomainardi requested that failed test be re-tested.

aren cambre’s picture

subscribe

v8powerage’s picture

Newest ajax comments module has ajax pager it works with advanced forum after very small changes in it's js file.

vikramy’s picture

subscribe

xandeadx’s picture

subscr

wooody’s picture

How are make ajax pager for home page .
Thanks

k.dani’s picture

This is one of the most shortcomings of the Drupal. Until this won't be developed, there is a temporary solution:
Drupal 6 + Views + Views Custom Fields: http://www.interworks.com/blogs/carmstrong/2011/12/13/rendering-ajax-pag...
Drupal 7 + Views + Views PHP.
Unfortunetly, the Views PHP only available in dev version, so it may not work properly, i haven't tried yet.

nhtwr400’s picture

Hi,
my theme_pager_wrapper() function in pager.inc is not call by writing
theme('pager_wrapper', $block_content, $pager_id); in module. Can you please let me know why it is not call.

nod_’s picture

Assigned: nedjo » Unassigned
Status: Needs review » Postponed

Let's look back at that once views and blocks & layouts are a bit more advanced.

nod_’s picture

Status: Postponed » Closed (won't fix)

views is in core. they have that.

nod_’s picture

Status: Closed (won't fix) » Closed (fixed)
maximpodorov’s picture

Version: 8.0.x-dev » 7.x-dev
Issue summary: View changes
Status: Closed (fixed) » Active

What about non-Views pagers for Drupal 7?

nod_’s picture

Status: Active » Closed (won't fix)

That's contrib material. I don't think it's realistic to expect that kind of new feature in D7.