Search code examples
drupal-7

Drupal pagination count issue while i try to filter the data


$table_sort = $query->extend('TableSort')->orderByHeader($header);    
$pager = $table_sort->extend('PagerDefault')->limit($pagerLimit); 
$result = $pager->execute();

I use this code for pagination,everything is fine until i'm using filter option. Page navigation link is visible even i have only one records which has come from filter by id.

For example:
By default i have 100 records in table,so we can see page navigation link,its good.

The problem is when i try to filter the records by id alone. I got only one record which is matched for given id but still now the pagination link is visible.


Solution

  • $countQuery = $query;
    $result = $query->execute();
    $Totalcount = $result->rowCount();
    $page = pager_default_initialize($Totalcount,$pagerLimit);