• 模拟google分页效果


     1 /// </summary>
     2     /// <param name="total">总记录数</param>
     3     /// <param name="per">每页记录数</param>
     4     /// <param name="page">当前页数</param>
     5     /// <param name="query_string">Url参数</param>
     6     private string pagination(int total, int per, int page, string query_string)
     7     {
     8         int allpage = 0;
     9         int next = 0;
    10         int pre = 0;
    11         int startcount = 0;
    12         int endcount = 0;
    13         string pagestr = "";
    14 
    15         if (page < 1) { page = 1; }
    16         //计算总页数
    17         if (per != 0)
    18         {
    19             allpage = (total / per);
    20             allpage = ((total % per) != 0 ? allpage + 1 : allpage);
    21             allpage = (allpage == 0 ? 1 : allpage);
    22         }
    23         next = page + 1;
    24         pre = page - 1;
    25         startcount = (page + 5) > allpage ? allpage - 9 : page - 4;//中间页起始序号
    26         //中间页终止序号
    27         endcount = page < 5 ? 10 : page + 5;
    28         if (startcount < 1) { startcount = 1; } //为了避免输出的时候产生负数,设置如果小于1就从序号1开始
    29         if (allpage < endcount) { endcount = allpage; }//页码+5的可能性就会产生最终输出序号大于总页码,那么就要将其控制在页码数之内
    30         pagestr = "" + allpage + "页&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
    31 
    32         pagestr += page > 1 ? "<a href="" + query_string + "?page=1">首页</a>&nbsp;&nbsp;<a href="" + query_string + "?page=" + pre + "">上一页</a>" : "首页 上一页";
    33         //中间页处理,这个增加时间复杂度,减小空间复杂度
    34         for (int i = startcount; i <= endcount; i++)
    35         {
    36             pagestr += page == i ? "&nbsp;&nbsp;<font color="#ff0000">" + i + "</font>" : "&nbsp;&nbsp;<a href="" + query_string + "?page=" + i + "">" + i + "</a>";
    37         }
    38         pagestr += page != allpage ? "&nbsp;&nbsp;<a href="" + query_string + "?page=" + next + "">下一页</a>&nbsp;&nbsp;<a href="" + query_string + "?page=" + allpage + "">末页</a>" : " 下一页 末页";
    39 
    40         return pagestr;
    41     }
  • 相关阅读:
    laravel扩展xls处理maatwebsite/excel
    php连接ftp
    sublime
    非对称加密
    cron以及在laravel中使用cron
    多任务-python实现-生成器相关(2.1.13)
    多任务-python实现-迭代器相关(2.1.12)
    多任务-python实现-协程(2.1.11)
    多任务-python实现-多进程文件拷贝器(2.1.10)
    多任务-python实现-进程pool(2.1.9)
  • 原文地址:https://www.cnblogs.com/servant/p/3223033.html
Copyright © 2020-2023  润新知