同一个页面显示多个分页实现

哎.  怎么说   不知道这个办法算不算牵强   不过这是小菜我最直接想到的办法.  效果图如下

 

代 码 部 分 : ( 请注意两个分页的变量是不一样的 但是调用的方法一样 所以只需要把变量名称通过参数传给方法再加以判断识别 )

   <!----分页-->
                    <div class="pagination">
                        <ul id="pagediv">
                            <li class="disabled"><a href="javascript:void(0);" onclick="previous('add')">上一页</a></li>
                            @for (int i = 1; i < ViewData["add_pageCount"].ToString().ToInt32() + 1; i++)
                            {
                                <li id="addpagenums_@i"><a href="#" id="addpagenum_@i" onclick="pageto(@i,'add')">@i</a></li>

                            }
                            <li><a href="javascript:void(0)" onclick="next('add')">下一页</a></li>
                        </ul>
                        <span class="page-total">共<span id="addcount">@ViewData["add_pageCount"]</span>  页</span>
                        <div class="jump">
                            到第
                            <input type="text" class="number" id="addtheNum">
                            页
                            <a href="#" class="submit" onclick="pageto('','add')">确定</a>
                        </div>
                    </div>
                </div>

 

   <!----分页-->
                    <div class="pagination" id="moredata">
                        <ul id="pagediv">
                            <li class="disabled"><a href="javascript:void(0);" onclick="previous('adj')">上一页</a></li>
                            @for (int i = 1; i < ViewData["adj_pageCount"].ToString().ToInt32() + 1; i++)
                            {
                                <li id="adjpagenums_@i"><a href="#" id="adjpagenum_@i" onclick="pageto(@i,'adj')">@i</a></li>

                            }
                            <li><a href="javascript:void(0)" onclick="next('adj')">下一页</a></li>
                        </ul>
                        <span class="page-total">共<span id="adjcount">@ViewData["adj_pageCount"]</span>  页</span>
                        <div class="jump">
                            到第
                            <input type="text" class="number" id="adjtheNum">
                            页
                            <a href="#" class="submit" onclick="pageto('','adj')">确定</a>
                        </div>
                    </div>
                </div>

 

JS 部 分 :  通过改变导航栏参数的数字来实现刷新数据

//跳转页面
    function pageto(num, obj) {
        var allcount = parseInt($("#" + obj + "count").text());
        if (num == "") {
            var num = parseInt($("#" + obj + "theNum").val());
        }

        if (num < 1 || num > allcount) {
            layer.msg("请选择有效页数")
        }
        else {
            if (obj == "adj")
                location.href = "/LegPlans/LegPlans/Index?adj=" + num + "&&add=" + GetQueryString("add");
            else
                location.href = "/LegPlans/LegPlans/Index?adj=" + GetQueryString("adj") + "&&add=" + num;
        }

    }

    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)
            return parseInt(unescape(r[2])); return null;
    }

    //当前页数加亮页码
    $(function () {
        var a = GetQueryString("adj");
        var b = GetQueryString("add");
        $("#adjpagenums_" + a).prop("class", "active");
        $("#addpagenums_" + b).prop("class", "active");
    })
    //下一页
    function next(obj) {
        var allcount = parseInt($("#" + obj + "count").text());
        var objpage = GetQueryString(obj) + 1;
        if (objpage > allcount) {
            layer.msg("已经是最后一页")
        }
        else {
            if (obj == "adj") {
                location.href = "/LegPlans/LegPlans/Index?adj=" + objpage + "&&add=" + GetQueryString("add");
                $("#moredata").css("display", "block")
            }
               
            else
                location.href = "/LegPlans/LegPlans/Index?adj=" + GetQueryString("adj") + "&&add=" + objpage;
               $("#moredata").css("display", "block")
        }

    }
    //上一页
    function previous(obj) {
        var allcount = parseInt($("#" + obj + "count").text());
        var objpage = GetQueryString(obj) - 1;
        if (objpage < 1) {
            layer.msg("已经是第一页")
        }
        else {
            if (obj == "adj") {
                location.href = "/LegPlans/LegPlans/Index?adj=" + objpage + "&&add=" + GetQueryString("add");
                $("#moredata").css("display", "block")
            }
               
            else
                location.href = "/LegPlans/LegPlans/Index?adj=" + GetQueryString("adj") + "&&add=" + objpage;
                $("#moredata").css("display", "block")
        }
    }

 

控 制 器 : ( 这里需要传到视图的变量有两个 : 数据总数  总页数  )

 

int size = 2;
            //计划建议调整 
            var suggest_adjustment = plansuggest.GetSuggest_adjustment(suggest, menu, name);
            ViewBag.suggest_adjustment = suggest_adjustment.Skip(size * (adj - 1)).Take(size);
            ViewData["adj_AllCount"] = suggest_adjustment.Count();   //总数
            double adj_pagecount = suggest_adjustment.Count() / size;   //分页
            if (suggest_adjustment.Count()%size == 0)
            {
                ViewData["adj_pageCount"] = Math.Ceiling(adj_pagecount);  //页数总数
            }
            else
            {
                ViewData["adj_pageCount"] = Math.Ceiling(adj_pagecount)+1;  //页数总数
            }

            //计划建议添加
            var suggest_add = plansuggest.GetSuggest_add(suggest, menu, name);
            ViewBag.suggest_add = suggest_add.Skip(size * (add - 1)).Take(size);

            ViewData["add_AllCount"] = suggest_add.Count();   //总数
            double add_pagecount = suggest_add.Count() / size;   //分页
            if (suggest_add.Count() % size == 0)
            {
                ViewData["add_pageCount"] = Math.Ceiling(add_pagecount);  //页数总数
            }
            else
            {
                ViewData["add_pageCount"] = Math.Ceiling(add_pagecount) + 1;  //页数总数
            }
            ViewData["sugCount"] = suggest_adjustment.Count() + suggest_add.Count();

 

如果您还有更方便的方法或者对本文有疑问欢迎Q(同Wechat) : 385587886

 

 

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 像素格子 设计师:CSDN官方博客 返回首页