C# 使用easyUI datagrid 实现后台分页

EASYUI DATAGRID 后台分页 C# 

前台

 

        <form id="log_Show_Ser_Form" style="margin: 2px; padding: 2px">
            <div>
                <span>查找方式:</span>
                <select onchange="change_Ser_Method()" class="easyui-combobox" id="ser_Method_Type">
                    <option value="user">当前用户</option>
                    <option value="department">当前科室</option>
                </select>
            </div>
            <div>
                <div id="cc" class="easyui-calendar"></div>
                <span>开始日期:</span><input id="strat_Date" style="width: 95px" class="easyui-datebox" data-options="sharedCalendar:'#cc'" />
                <span>结束日期:</span><input id="end_Date" style="width: 95px" class="easyui-datebox" data-options="sharedCalendar:'#cc'" />
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="queryreport()" style="width: 80px">查询</a>
            </div>
        </form>

 

 

 

 

 

JS部分

 

 $(function () {
            $('#gd_Show_Import_Sampe').datagrid({
                title: '记录',
                height: 'auto',
                nowrap: false,
                striped: true,
                border: true,
                collapsible: false,//是否可折叠的 
                fit: true,//自动大小 
                remoteSort: false,
                idField: 'Id',
                singleSelect: false,//是否单选 
                pagination: true,//分页控件 
                rownumbers: true,//行号  
                pageList:[10],//固定10行查询
                columns: [[
                    { field: 'Id', title: 'Id', width: 80, hidden: true },
                    { field: 'PatientID', title: '标识', width: "10%", align: 'center' },
                    { field: 'PatientName', title: '姓名', width: "10%", align: 'center' },
                    { field: 'SexFlag', title: '性别', width: "10%", align: 'center' },
                    { field: 'Import_Date', title: '日期', width: "15%", align: 'center' },
                    { field: 'TB_CONSENT_FORM', title: 'XXX', width: '10%', align: 'center' },
                    { field: 'Others', title: 'XXX', width: '40%', align: 'center' },
                ]]
            });
            //当分页时运行
            var pager = $("#gd_Show_Import_Sampe").datagrid("getPager");
            pager.pagination({
                onSelectPage: function (pageNo, pageSize) {
                    var type = change_Ser_Method();//根据查询类型获取值
                    var stratDate = $('#strat_Date').textbox('getValue');
                    var endDate = $('#end_Date').textbox('getValue');
                    getDataForPage(type, stratDate, endDate, pageNo, pageSize);
                }
            });
        });

查询按钮的JS方法:

 

function queryreport() {
            var type = change_Ser_Method();//根据查询类型获取值
            var stratDate = $('#strat_Date').textbox('getValue');
            var endDate = $('#end_Date').textbox('getValue');
            if (stratDate == "" || endDate == "") { $.messager.alert('错误', '查询日期不能为空', 'error'); return; }
            else {
                if (!dateCompare) { $.messager.alert('错误', '开始日期不能大于结束日期', 'error'); return; }
                else {
                    getDataForPage(type, stratDate, endDate, 0, 0);
                }
            }
        }
</pre><pre code_snippet_id="1733946" snippet_file_name="blog_20160628_5_7475488" name="code" class="javascript">function getDataForPage(type, stratDate, endDate, pageNo, pageSize) {
<span style="white-space:pre">		</span> //设置开始页码和结束页码
            var startCount;
            var endCount;
            if (pageNo != 0 && pageSize!=0) {
                startCount = (pageNo - 1) * pageSize;
                endCount = startCount + pageSize;
            }
<span style="white-space:pre">		</span>//获取远程服务器的数据
            $.ajax({
                type: 'GET',
                url: '/Fp_Ajax/GetData.aspx?action=getLogImport',
                data: {
                    Importtype: type,
                    stratDate: stratDate,
                    endDate: endDate,
                    startCount: startCount,
                    endCount: endCount
                },
                onSubmit: function () { },
                success: function (data) {
                    if (data != "") {
                        var objdata = JSON.parse(data);
                        var total = objdata.Total;
                        if (total > 0) {
<span style="white-space:pre">					</span>//数据转换<span style="white-space:pre">	</span>
                            var jsondata = objdata.JsonData;
                            var ds = jsondata.ds;
                            $('#gd_Show_Import_Sampe').datagrid('loadData', ds);
                            var pager = $("#gd_Show_Import_Sampe").datagrid("getPager");
                            var count = 10;
                            pager.pagination({
                                total: total,
                                pageNumber: pageNo
                            });
                        }
                    }
                }
            });
        }


前台方面只要数据返回之后 根据页码就可以绑定上去

 

二、后台代码:

                string strJson = "";
                string strGetDataType = "";
                string strImportType = Request.Params["Importtype"].ToString();
                string[] array = strImportType.Split('-');
                //获取传入的时间
                string strStartDate = Request.Params["stratDate"].ToString();
                string strendDate = Request.Params["endDate"].ToString();
                //获取页码
                int startCount = Convert.ToInt32(Request["startCount"]);
                int endCount = Convert.ToInt32(Request["endCount"]);
 <span style="white-space:pre">		</span>//当第一次获取时,默认获取前10的数据
          if (startCount==0||endCount==0){startCount = 1;endCount = 10;}
          else if (startCount>1){endCount = startCount+10-1;}
<span style="white-space:pre">	</span>       strJson = log_bll.GetDate(strGetDataType, "", strStartDate, strendDate, startCount, endCount);
<span style="white-space:pre">	</span>       Response.Write(strJson);
</pre><p>后台代码需要注意的是,需要将数据返回为JSON数据格式:</p><p></p><pre code_snippet_id="1733946" snippet_file_name="blog_20160628_14_4292287" name="code" class="plain">{"Total":"51","JsonData":{"ds":[{"Row":1,"Id":71,"PatientID":1000456613,"Import_Date":"2016-06-23T00:00:00","Import_State":true,"Import_Date_Msg":"{\"success\":true,\"msg\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"message\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"status\":\"DONE\",\"job_id\":\"importers:import:b7d9ede1cd0cafacefb54a7629f4a777\"}","Import_User_Id":"xys","Import_User_Department":"心研所","Import_Type":"sample","Others":"上清-心研所:5管;上清-心研所:5管","PatientName":"黄燕娥","SexFlag":"女","TB_CONSENT_FORM":"无"},{"Row":2,"Id":70,"PatientID":1000456613,"Import_Date":"2016-06-23T00:00:00","Import_State":true,"Import_Date_Msg":"{\"success\":true,\"msg\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"message\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"status\":\"DONE\",\"job_id\":\"importers:import:b7d9ede1cd0cafacefb54a7629f4a777\"}","Import_User_Id":"xys","Import_User_Department":"心研所","Import_Type":"sample","Others":"上清-心研所:5管;上清-心研所:5管","PatientName":"黄燕娥","SexFlag":"女","TB_CONSENT_FORM":"无"},{"Row":3,"Id":69,"PatientID":1000456613,"Import_Date":"2016-06-23T00:00:00","Import_State":true,"Import_Date_Msg":"{\"success\":true,\"msg\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"message\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"status\":\"DONE\",\"job_id\":\"importers:import:b7d9ede1cd0cafacefb54a7629f4a777\"}","Import_User_Id":"xys","Import_User_Department":"心研所","Import_Type":"sample","Others":"上清-心研所:5管;上清-心研所:5管","PatientName":"黄燕娥","SexFlag":"女","TB_CONSENT_FORM":"无"},{"Row":4,"Id":68,"PatientID":1000456613,"Import_Date":"2016-06-23T00:00:00","Import_State":true,"Import_Date_Msg":"{\"success\":true,\"msg\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"message\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"status\":\"DONE\",\"job_id\":\"importers:import:b7d9ede1cd0cafacefb54a7629f4a777\"}","Import_User_Id":"xys","Import_User_Department":"心研所","Import_Type":"sample","Others":"上清-心研所:5管;上清-心研所:5管","PatientName":"黄燕娥","SexFlag":"女","TB_CONSENT_FORM":"无"},{"Row":5,"Id":67,"PatientID":1000456613,"Import_Date":"2016-06-23T00:00:00","Import_State":true,"Import_Date_Msg":"{\"success\":true,\"msg\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"message\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"status\":\"DONE\",\"job_id\":\"importers:import:b7d9ede1cd0cafacefb54a7629f4a777\"}","Import_User_Id":"xys","Import_User_Department":"心研所","Import_Type":"sample","Others":"上清-心研所:5管;上清-心研所:5管","PatientName":"黄燕娥","SexFlag":"女","TB_CONSENT_FORM":"无"},{"Row":6,"Id":66,"PatientID":1000456613,"Import_Date":"2016-06-23T00:00:00","Import_State":true,"Import_Date_Msg":"{\"success\":true,\"msg\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"message\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"status\":\"DONE\",\"job_id\":\"importers:import:b7d9ede1cd0cafacefb54a7629f4a777\"}","Import_User_Id":"xys","Import_User_Department":"心研所","Import_Type":"sample","Others":"上清-心研所:5管;上清-心研所:5管","PatientName":"黄燕娥","SexFlag":"女","TB_CONSENT_FORM":"无"},{"Row":7,"Id":65,"PatientID":1000456613,"Import_Date":"2016-06-23T00:00:00","Import_State":true,"Import_Date_Msg":"{\"success\":true,\"msg\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"message\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"status\":\"DONE\",\"job_id\":\"importers:import:b7d9ede1cd0cafacefb54a7629f4a777\"}","Import_User_Id":"xys","Import_User_Department":"心研所","Import_Type":"sample","Others":"上清-心研所:5管;上清-心研所:5管","PatientName":"黄燕娥","SexFlag":"女","TB_CONSENT_FORM":"无"},{"Row":8,"Id":64,"PatientID":1000456613,"Import_Date":"2016-06-23T00:00:00","Import_State":true,"Import_Date_Msg":"{\"success\":true,\"msg\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"message\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"status\":\"DONE\",\"job_id\":\"importers:import:b7d9ede1cd0cafacefb54a7629f4a777\"}","Import_User_Id":"xys","Import_User_Department":"心研所","Import_Type":"sample","Others":"上清-心研所:5管;上清-心研所:5管","PatientName":"黄燕娥","SexFlag":"女","TB_CONSENT_FORM":"无"},{"Row":9,"Id":63,"PatientID":1000456613,"Import_Date":"2016-06-23T00:00:00","Import_State":true,"Import_Date_Msg":"{\"success\":true,\"msg\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"message\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"status\":\"DONE\",\"job_id\":\"importers:import:b7d9ede1cd0cafacefb54a7629f4a777\"}","Import_User_Id":"xys","Import_User_Department":"心研所","Import_Type":"sample","Others":"上清-心研所:5管;上清-心研所:5管","PatientName":"黄燕娥","SexFlag":"女","TB_CONSENT_FORM":"无"},{"Row":10,"Id":62,"PatientID":1000456613,"Import_Date":"2016-06-23T00:00:00","Import_State":true,"Import_Date_Msg":"{\"success\":true,\"msg\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"message\":\"10 \\u6761\\u8bb0\\u5f55\\u6210\\u529f\\u5bfc\\u5165.\",\"status\":\"DONE\",\"job_id\":\"importers:import:b7d9ede1cd0cafacefb54a7629f4a777\"}","Import_User_Id":"xys","Import_User_Department":"心研所","Import_Type":"sample","Others":"上清-心研所:5管;上清-心研所:5管","PatientName":"黄燕娥","SexFlag":"女","TB_CONSENT_FORM":"无"}]}}


由于是直接使用dataset转换的 所以需要解析多一遍

 

 

本文仅用记录,目前参考价值不大

 

 

 

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值