最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the best way to implement backend pagination using angularJS? - Stack Overflow

programmeradmin3浏览0评论

I have a situation where I want to implement back end pagination but, I am not sure about how to do it. I am thinking of a solution where I fetch the total pages (a page is a list of n defined element ) and then make call to the server to fetch 1st, 2nd, 3rd, 4th , .... n-th page and so on. Any suggestions ?

I have a situation where I want to implement back end pagination but, I am not sure about how to do it. I am thinking of a solution where I fetch the total pages (a page is a list of n defined element ) and then make call to the server to fetch 1st, 2nd, 3rd, 4th , .... n-th page and so on. Any suggestions ?

Share Improve this question asked Nov 12, 2012 at 12:22 AdelinAdelin 19k27 gold badges129 silver badges197 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

Generally, pagination is done by specifying to the user how many results to display per page, and which page of results he is currently viewing. However, backend storage such as MySQL or Solr typically handle pagination by specifying how many results to display per page, and how many results to skip in the output. I generally use something like the following PHP to get the later (for the backend) out of the former (from the user):

$documentsPerPage = 10;

if ( isset($input['page']) && is_numeric($input['page']) && $input['page']>0 ) { 
    $skip = $documentsPerPage * (intval($input['page'])-1);
} else {
    $skip =0;
}

$sql = "SELECT * FROM someTable LIMIT {$skip}, {$documentsPerPage}";

If you have $count records in the database, here is how to calculate how many pages you have with a simulated floor-up operation:

$totalPages = ($count + $documentsPerPage - 1) % $documentsPerPage;
发布评论

评论列表(0)

  1. 暂无评论