LigerUI Server端实现分页

8 篇文章 0 订阅
4 篇文章 0 订阅

前台JS代码:

<script type="text/javascript" language="javascript">
        $(f_initGrid);
        var grid;
        function f_initGrid() {
            grid = $("#maingrid").ligerGrid({
                columns: [
                {display:'前缀',name:'prefix',width: 100},
                { display: '编码', name: 'parts_no', width: 100},
                { display: '配件编码', name: 'prefix_parts_no', width: 100}],
                url: 'Ashx/GetPartsList.ashx?Action=GetData', //一般处理程序
                dataAction: 'server',//服务器排序
                usePager:true
            });
        }

        function f_search() {  
            grid.options.parms.where1 = "111";  //查询条件
            grid.loadData(true);
        }
</script>


Ashx代码:


public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string result=string.Empty;

            string action = context.Request.Params["Action"];
            string where = context.Request.Params["where1"];
            string sortname = context.Request.Params["sortname"]; //排序名称
            string sortorder = context.Request.Params["sortorder"]; //排序方式
            string pageSize = context.Request.Params["pagesize"];
            string page = context.Request.Params["page"];

            int page_size_int = 10;
            int page_int = 1;
            if (!string.Empty.Equals(SalesCommon.GetIsNullOrEmpty(page))) int.TryParse(page, out page_int);
            if (!string.Empty.Equals(SalesCommon.GetIsNullOrEmpty(pageSize))) int.TryParse(pageSize, out page_size_int);
            page_int = page_int - 1;

            IList<Node> list = new List<Node>();
            string sql = "select prefix,parts_no,prefix_parts_no from sales_order_detail where ifnull(prefix,'')<>'' ";

            if (!string.Empty.Equals(SalesCommon.GetIsNullOrEmpty(sortname)))
            {
                sql += " order by " + sortname + " " + sortorder;
            }
            else
            {
                sql += " order by create_date desc ";
            }

            sql += " limit " + page_int * page_size_int + "," + page_size_int;
           
            DataTable dt = SalesCommon.QueryTable(sql);

            for (var i = 0; i < dt.Rows.Count; i++)
            {
                list.Add(new Node()
                {
                    prefix = dt.Rows[i]["prefix"].ToString(),
                    parts_no = dt.Rows[i]["parts_no"].ToString(),
                    prefix_parts_no = dt.Rows[i]["prefix_parts_no"].ToString()
                });
            }
           
            sql = "select count(1) cnt from sales_order_detail where ifnull(prefix,'')<>''";
            dt = SalesCommon.QueryTable(sql);
            int page_count=0;
            if (dt != null && dt.Rows.Count > 0) int.TryParse(SalesCommon.GetIsNullOrEmpty(dt.Rows[0]["cnt"]), out page_count);

            var griddata = new { Rows = list, Total = page_count };
            result = new JavaScriptSerializer().Serialize(griddata);

            context.Response.Write(result);
            context.Response.End();
        }


        //字段属性

        class Node
        {
            public string prefix { get; set; }
            public string parts_no { get; set; }
            public string prefix_parts_no { get; set; }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值