jquery-pager分页

首先引用这三个文件

<script src="../../Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-pager-1.0.js" type="text/javascript"></script>
<link href="../../Scripts/pager.css" rel="stylesheet" type="text/css" />

 

HTML


<
body> <div> <div class="title"> <h1> 工作量统计表</h1> </div> <table width="50%" border="1" class="t1"> <thead> <th> 墓型代码 </th> <th> 墓型名称 </th> <th> 面积 </th> <th> 单价 </th> <th> 累计建墓 </th> </thead> <tbody style="text-align: center; font-size: 12px; color: black;"> </tbody> </table> <br /> <div id="page-bottom" style="width: 55%; border: 1px;" class="pageinfo"> </div> </div> </body>

 

前端代码:

<script language="javascript" type="text/javascript">
        //得到页面数据总数
        function getPageCount() {
            var result = "";
            $.ajax({
                type: "POST",
                url: "/Manager/WorkStatistic/PageGetCount",
                cache: "false",
                async: false,
                success: function (data) {
                    result = eval(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("程序异常!");
                }
            });
            return result;
        };
        $(document).ready(function () {
            //加载页数及页码
            var recordCount = getPageCount();
            InitPager(recordCount, 1);
        });
        function Init(PageIndex, PageCount) {
            var receive_url = "/Manager/WorkStatistic/WorkStatistics?pageIndex=" + PageIndex + "&PageCount=" + PageCount;
            $.ajax({
                type: "GET",
                url: receive_url,
                cache: "false",
                success: function (data) {
                    data = eval(data);
                    $("tbody").html("");
                    var html = "";
                    for (var i = 0; i < data.length; i++) {
                        var json = data[i];
                        var mxdm = json.mxdm;
                        var mxdmmc = json.mxdmmc;
                        var mj = json.mj;
                        var dj = json.dj;
                        var ljjm = json.ljjm;
                        html += "<tr><td>" + mxdm + "</td><td>" + mxdmmc + "</td><td>" + mj + "</td><td>" + dj + "</td><td>" + ljjm + "</td></tr>";
                    }
                    $("tbody").append(html);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("程序异常!");
                }
            });
        };
        //RecordCount[总记录数] PageIndex[当前页码]
        function InitPager(RecordCount, PageIndex) {
            $("#page-bottom").setPager({ RecordCount: RecordCount, PageIndex: PageIndex, buttonClick: PageClick });
            //分页同时更新数据源
            Init(PageIndex, 20);
        };
        //分页事件
        PageClick = function (RecordCount, PageIndex) {
            InitPager(RecordCount, PageIndex);
        };
    </script>

 

客户端代码:

        public ActionResult WorkStatistics()
        {
            string pageIndex = Request.Params.Get("PageIndex");
            string pageCount = Request.Params.Get("PageCount");
            int page = Convert.ToInt32(pageIndex) * Convert.ToInt32(pageCount);
            string SQL_Init = @"SELECT * FROM ( SELECT rownum RN,t.* FROM ( SELECT a.mxdm,a.mxdmmc,a.mj,AVG((SELECT dj FROM mxdm WHERE a.mxdm= mxdm)) dj,COUNT(*) ljjm"
                + " FROM mwdmxx a WHERE a.azfsdm= '01' GROUP BY a.mxdm ,a.mxdmmc,a.mj ORDER BY a.mxdm) t WHERE  rownum <=" + page + ") WHERE RN > " + (page - Convert.ToInt32(pageCount));

            DataSet ds = DBhelper.Query(SQL_Init);
            //实例化结构体数组
            TombType_SaleInfo[] result = new TombType_SaleInfo[ds.Tables[0].Rows.Count];
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                string mxdm = ds.Tables[0].Rows[i]["MXDM"].ToString();
                string mxdmmc = ds.Tables[0].Rows[i]["MXDMMC"].ToString();
                double mj = Double.Parse(ds.Tables[0].Rows[i]["MJ"].ToString() == "" ? "0" : ds.Tables[0].Rows[i]["MJ"].ToString());
                int dj = Int32.Parse(ds.Tables[0].Rows[i]["DJ"].ToString() == "" ? "0" : ds.Tables[0].Rows[i]["DJ"].ToString());
                int ljjm = Int32.Parse(ds.Tables[0].Rows[i]["LJJM"].ToString() == "" ? "0" : ds.Tables[0].Rows[i]["LJJM"].ToString());

                TombType_SaleInfo temp = new TombType_SaleInfo(mxdm, mxdmmc, mj, dj, ljjm);
                result[i] = temp;
            }
            return Json(result, JsonRequestBehavior.AllowGet);
        }
        //得到数据总条数
        public void PageGetCount()
        {
            string SQL_Init = @"SELECT count(*) FROM (SELECT count(a.mxdm)  FROM mwdmxx a WHERE a.azfsdm= '01' GROUP BY a.mxdm ,a.mxdmmc,a.mj )";
            string count = DBhelper.GetScalar(SQL_Init);
            Response.Write(count);
            Response.End();
        }

 

posted @ 2014-07-11 10:41  韩梦芫  阅读(2139)  评论(0编辑  收藏  举报