Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By vickey on
To add Pager in custom table view, append the following code (line 1 & 2) in your module.
$query = db_select('mymodule', 'mym');
$query->fields('mym');
$query = $query->extend('PagerDefault')->limit(5); // line1
$result = $query->execute();
..
$output = theme('table',..
$output .= theme('pager'); // line2
return $output;
Comments
You are asking on telling
You are asking on telling others?
Just for sharing info
I sharing(telling) this info to all who new to drupal 7
Good information
Thk for sharing, where i search for pager one array with no db_select (direct multiarray)?
Bye !
lgrtm, you are maybe
lgrtm, you are maybe interested on this:
via: http://chacadwa.com/blog/2013/03/12/drupal-7-display-array-contents-pager
With out db_query Or for array content
---
Kind regards,
Thank you,
Rakesh James
help
rakesh.gectcr That was very helpful, but i can't seem to limit the number of records displayed.
What does your code look like
What does your code look like?
I was able to solve the problem
I was able to go about the problem. I could Limit my pager to any amount by just changing the value in "limit(value)" I set mine to 50. And the header is sticky too. Thanks yall! Here is the code sorry its a bit messy.
Great! Thanks Rakesh.
Great! Thanks Rakesh.
Thanks Rakesh for the simple
Thanks Rakesh for the simple and understandable solution.
Hi,
Hi,
how to add id to this pager so that it is applied only for this part of the code.
thanks
Use the parameter 'element' to override the theme function
Hi mahianu,
if your goal is to add an HTML id to the pager, you could take advantage of the variable 'element', designed to be unique and distinguish between several pagers in the same page, to override the theme function and add wrap the element with a container with an unique id.
You could do it in the template.php of your theme:
Using the pager theme as, for example:
will create a container like:
I applied above method in
I applied above method in views tpl. When i click on pager number, My table data does empty. Any solution please.?
Great way to output pager
Thanks rakesh,
This is very useful to create pagers for rows available in array. Very helpful.
I know this is three years old but ...
Drupal docs says to avoid calling theme() directly:
That does not apply to theme
That does not apply to theme implementations that are overriding the theme you are calling. If you follow that guideline you will wind up with a recursion where your theme function calls itself.
Drupal will translate the render array into
theme('pager')
which then goes through the normal theming process and will callMYTHEME_pager
again. Callingtheme_pager()
directly in the theme implementation bypasses that process within Drupal.The downside is if anything else is modifying pagers it may not have a chance to act.
It works for me
rakesh.gectcr It works for me.Thanks
Thanks
Thanks @rakesh.gectcr
To have sortable tables with db_select
Thanks @rakesh.getctcr! If someone need tablesort on it you could use db_select and do it like so:
An exemple of pagination
//an exemple
function collection_list(){
// définir le header du tableau
$header = array(
array('data' => t('Titre'), 'field' => 'title', 'sort' => 'ASC'),
);
// recupération des collection
$collections = db_select('node', 'n')
->fields('n')
->condition('n.type', 'collection', '=')
->execute()
->fetchAll();
// definir les lignes
foreach($collections as $collection){
$rows[] = array(
'<a href="language/translate/collection/'.$collection->nid.'">'.$collection->title.'</a>'
);
}
// nombre par page
$per_page = 10;
$current_page = pager_default_initialize(count($rows), $per_page);
$split_list = array_chunk($rows, $per_page, TRUE);
// faire le rendu
$output = theme('table', array(
'header' => $header,
'rows' => $split_list[$current_page]
));
// ajout de la pagination
$output .= theme('pager');
return $output;
}
Excuse my bad English, i'm
Excuse my bad English, i'm afraid that
Is not correct, it would be like this:
Even better:
Thanks, its save my time.
Thanks @rakesh.gectcr, its save my time.
Unable to render pager in Drupal 7 page - setCounterQuery
execute() method triggers error "Call to a member function execute() on null"
Removing the setCountQuery() method call alleviates the immediate problem but I"m afraid won't be able to render pager
Any ideas what am I doing wrong ?
setCountQuery does not return
setCountQuery does not return anything. You are assigning null to $query. You must create your query and then call setCountQuery separately.
setCountQuery
On what object am I supposed to envoke setCountQuery then ?