我正在寻找智能分页的示例算法。聪明地说,我的意思是,例如,我只想显示当前页面的2个相邻页面,因此我截断了它而不是结束一个冗长的页面列表。
这是一个简单的例子,可以使它更清楚……这就是我现在所拥有的:
Pages: 1 2 3 4 [5] 6 7 8 9 10 11
这就是我要结束的事情:
Pages: ... 3 4 [5] 6 7 ...
(在此示例中,我仅显示当前页面的2个相邻页面)
我正在PHP /
Mysql中实现它,并且已经对“基本”分页(没有任何删节)进行了编码,我只是在寻找一个示例来对其进行优化……只要可以,就可以是任何语言的示例它给我一个关于如何实现它的想法…
前一段时间我也有同样的需求。
这是我用来完成此工作的文章(使用PHP代码):
Digg样式分页
它的运行速度非常快,并且为您尝试做的事情增加了一些内容,例如:
[1] 2 3 4 5 6 ... 100
1 [2] 3 4 5 6 ... 100
...
1 ... 4 5 [6] 7 8 ... 100
这是来自断开链接的代码:
<?php
/*
Place code to connect to your DB here.
*/
// How many adjacent pages should be shown on each side?
$adjacents = 3;
/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "SELECT COUNT(*) as num FROM portfolio";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
/* Setup vars for query. */
$limit = 2; //how many items to show per page
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0
/* Get data. */
$query = "SELECT category, uname, title FROM portfolio LIMIT $start, $limit";
$portfolio = mysql_query($query);
/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class="\"pagination\"">";
//previous button
if ($page > 1)
$pagination.= "<a href="\"diggstyle.php?page=$prev\"">« previous</a>";
else
$pagination.= "<span class="\"disabled\"">« previous</span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class="\"current\"">$counter</span>";
else
$pagination.= "<a href="\"diggstyle.php?page=$counter\"">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class="\"current\"">$counter</span>";
else
$pagination.= "<a href="\"diggstyle.php?page=$counter\"">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href="\"diggstyle.php?page=$lpm1\"">$lpm1</a>";
$pagination.= "<a href="\"diggstyle.php?page=$lastpage\"">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href="\"diggstyle.php?page=1\"">1</a>";
$pagination.= "<a href="\"diggstyle.php?page=2\"">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class="\"current\"">$counter</span>";
else
$pagination.= "<a href="\"diggstyle.php?page=$counter\"">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href="\"diggstyle.php?page=$lpm1\"">$lpm1</a>";
$pagination.= "<a href="\"diggstyle.php?page=$lastpage\"">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href="\"diggstyle.php?page=1\"">1</a>";
$pagination.= "<a href="\"diggstyle.php?page=2\"">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class="\"current\"">$counter</span>";
else
$pagination.= "<a href="\"diggstyle.php?page=$counter\"">$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a href="\"diggstyle.php?page=$next\"">next »</a>";
else
$pagination.= "<span class="\"disabled\"">next »</span>";
$pagination.= "</div>\n";
}
?>
<ul>
<?php
while($item = mysql_fetch_array($portfolio))
{
?>
<li><a href="/web/20080709045706/http://www.strangerstudios.com/portfolio//"></a></li>
<?php
}
?>
</ul>
<?=$pagination?>
我目前正在使用:“angular smart table”:“2.1.0”“angular”:“1.3.15” 单击智能表格项目时,我的应用程序会在另一个页面中显示项目详细信息。在访问项目页面后,我想回到智能表格页面上的相同页码(屏幕截图上的2):屏幕截图 我的问题: 不知道如何保存currentPage(rootscope、Parameter?) 以下是分页视图,用于管理分页: “智能表插件指令
我正在使用智能表插件进行分页。 我的要求是-我从数据库中获取100条记录,同时加载,每页记录为10条。所以,分页的页数将是10页。 现在,我想当我点击第10页时(从分页),然后我想从数据库中获取另外100条记录
我在Angular 2应用程序中使用ng2智能表,其中的分页有问题。我正在加载一个数据对象数组,它正确地显示了前五个(我总共有20个),但表底部的分页显示 你知道为什么会这样吗
我的页面正在成功加载智能表js,但是当我尝试使用分页功能(如留档所示)时,我收到以下错误 和 我不确定我做错了什么,但下面是我的代码。任何帮助都会很好!谢谢
通过使用角智能表,如何使用偏移值获得结果集。比如我数据库里有100条记录 首先,我需要从数据库中获取20条记录,并且每页只显示10个项目。 点击第三页后,需要查询数据库(服务调用)并获取另外20条记录... etc(但第二页没有服务器调用) 我正在使用SmartTablePipe/ajax插件来显示记录。 如何使用这个来实现。 http://lorenzofox3.github.io/smart-
单条分单 批量分单 订单状态统计 按图层订单统计 全部订单统计