Posted by tomas.teicher on December 6, 2012 at 3:46pm
Is it somehow possible to set pager joined with db_select to work with ajax? I would like to refresh table content with ajax pager.
IS it possible similar like in views?
Is it somehow possible to set pager joined with db_select to work with ajax? I would like to refresh table content with ajax pager.
IS it possible similar like in views?
Comments
You can append the page
You can append the page number as a GET request to the callback URL. So if you are requesting data from module/ajax_callback, you can request module/ajax_callback?page=1. As long as you do a proper pager query in your AJAX callback, a pager can also be generated in the callback, and returned to the AJAX.
There is one caveat however. When generating the pager, since the query is done in the scope of the AJAX callback, and not the original page load, any links generated in the pager will not work. If my memory serves me correctly, you can put the following code at the top of your AJAX callback. Imagine your original page load is at the following path: /path/to/my/content:
<?php$_GET['q'] = 'path/to/my/content';
?>
Drupal uses the GET variable 'q' for paths, as is seen clean URLs turned off. The 'q' variable is still there even when clean URLs are turned on, but they are invisible to the user. By setting this value in your AJAX callback, you essentially are tricking the system into thinking it's on the original page, rather than in an AJAX callback, and this should render your pager links so that they are pointing to the correct path.
Jaypan We build websites