Jump to content

Pagination in Modules


SwiftModders

Recommended Posts

Hi All,

I am working on a new module and I know there will be instances where a number of records will be pulled into view. Does WHMCS provide a way to handle pagination of records or should I use the Laravel pagination method?

Source: https://laravel.com/docs/5.2/pagination

I am curious how other developers do it or if you do your own custom pagination method.

Link to comment
Share on other sites

I have no experience with Lavarel but maybe you could simply include the missing "pagination" component/script.

Anyway keep in mind that Laravel is inflexible. Let me quote just this thing from their documentation:

Currently, pagination operations that use a groupBy statement cannot be executed efficiently by Laravel. If you need to use a groupBy with a paginated result set, it is recommended that you query the database and create a paginator manually.

😑 so what's the point of using it? Anyway it should be fine if you don't need to filter results with GROUP BY.

 

Link to comment
Share on other sites

  • 1 month later...
On 2/28/2020 at 10:12 PM, SwiftModders LLC said:

I see, it also appears that WHMCS is not including the Laravel pagination as I cannot call it. Ugh. Any recommendations on alternative pagination functions?

 

This is how I would do it.

replace YOURTABLE with your table name and .COL with your column name and you can add as much as you link
just add {$HTMLpagePagination} somewhere in your returned html code. This is compatible with bootstrap so you can play with the classes to change the design.

$record_count = Capsule::table('YOURTABLE')->count();
$offset=10;
$offsets=$record_count/$offset;
if (!$_REQUEST['page']){$page = 1;}else{$page = $_REQUEST['page'];}

if ($record_count != null)
{
$record_list = Capsule::table('YOURTABLE')
				->select('YOURTABLE.COL1','YOURTABLE.COL2')
                ->offset(($page-1)*$offset)
                ->limit($offset)
                ->get();
}

$HTMLpagePagination = "";
        if ($record_count < $offset+1){
        $HTMLpagePagination .= '<div class="clearfix">';
        $HTMLpagePagination .= '<div class="hint-text pull-left">Showing <b>'.$record_count.'</b> out of <b>'.$record_count.'</b> pages</div>';
        $HTMLpagePagination .= '</div>';}
        if ($record_count > $offset){
        $HTMLpagePagination .= '<div class="clearfix">';
        if ($page*$offset<$record_count){$HTMLpagePagination .= '<div class="hint-text pull-left">Showing <b>'.$page*$offset.'</b> out of <b>'.$record_count.'</b> pages</div>';}
        else{$HTMLpagePagination .= '<div class="hint-text pull-left">Showing <b>'.$record_count.'</b> out of <b>'.$record_count.'</b> pages</div>';}
        $HTMLpagePagination .= '<ul style="margin:0px 0px" class="pagination pull-right">';
        if ($page<2){$HTMLpagePagination .= '<li class="page-item disabled"><a href="#">Previous</a></li>';}
        else{$HTMLpagePagination .= '<li class="page-item"><a href="'.$modulelink.'&page='.($page-1).'">Previous</a></li>';}
        if ($page-2>0){$HTMLpagePagination .= '<li class="page-item"><a href="'.$modulelink.'&page='.($page-2).'" class="page-link">'.($page-2).'</a></li>';}
        if ($page-1>0){$HTMLpagePagination .= '<li class="page-item"><a href="'.$modulelink.'&page='.($page-1).'" class="page-link">'.($page-1).'</a></li>';}
        $HTMLpagePagination .= '<li class="page-item active"><a href="'.$modulelink.'&page='.($page).'" class="page-link">'.($page).'</a></li>';
        if ($page+1<$offsets+1){$HTMLpagePagination .= '<li class="page-item"><a href="'.$modulelink.'&page='.($page+1).'" class="page-link">'.($page+1).'</a></li>';}
        if ($page+2<$offsets+1){$HTMLpagePagination .= '<li class="page-item"><a href="'.$modulelink.'&page='.($page+2).'" class="page-link">'.($page+2).'</a></li>';}
        if ($page+1<$offsets+1){$HTMLpagePagination .= '<li class="page-item"><a href="'.$modulelink.'&page='.($page+1).'" class="page-link">Next</a></li>';}
        else{$HTMLpagePagination .= '<li class="page-item disabled"><a href="#" class="page-link">Next</a></li>';}
        $HTMLpagePagination .= '</ul>';
        $HTMLpagePagination .= '</div>';

If you need any further help or explanation.  please do not hesitate to ask, I am willing to help.
Good luck

Link to comment
Share on other sites

3 hours ago, weelow said:

This is how I would do it.

replace YOURTABLE with your table name and .COL with your column name and you can add as much as you link
just add {$HTMLpagePagination} somewhere in your returned html code. This is compatible with bootstrap so you can play with the classes to change the design.

Thanks! I ended up coming up with my own solution, but this is definitely helpful information for everyone 🙂

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated