LigerUI 分页 MVC

Javascirpt代码

$("#showData").ligerGrid({
                        columns: [
                                    { display: ‘编号‘, name: ‘L_ID‘, align: ‘center‘, width: 70 },
                                    {display: ‘时间‘, name: ‘L_TIME‘, minWidth: 120, type: ‘date‘, format: ‘yyyy-MM-dd HH:mm‘ },
                                    { display: ‘经度‘, name: ‘L_LONGITUDE‘, width: 90, align: ‘left‘ },
                                    { display: ‘纬度‘, name: ‘L_LATITUDE‘, width: 80, align: ‘left‘ },
                                    { display: ‘强度‘, name: ‘L_CURRENT‘, width: 50 },
                                    { display: ‘回击数‘, name: ‘L_RETIMES‘, width: 50 },
                                    { display: ‘定位站数‘, name: ‘L_STATIONNUM‘, width: 50 }
                        ], //绑定相应的列的头部,参数可以自己按照需求设置
                        //data: dataList, //数据
                        url: ‘../../LightningSearch/GetLightningByTime?stime=‘ + $("#txtStime").val() + ‘&etime=‘ + $("#txtEtime").val() +  ‘‘,
                        pageSizeOptions: [10, 20,30,],
                        pageSize: 15, //每一页显示多少条数据
                        sortName: ‘L_ID‘, //以那一列排序
                        width: ‘auto‘, //宽度
                        height: ‘515‘, dateFormat: ‘yyyy-MM-dd HH:mm‘,
                        checkbox: false//是否有选择框
                    });
View Code

ActionResult

 public ActionResult GetLightningByTime()
        {
            //当前页
            int page = Convert.ToInt32(Request.Params["page"]);
            //每页显示的记录数
            int pageSize = Convert.ToInt32(Request.Params["pagesize"]);
            string stime = Request.Params["stime"].ToString();
            string etime = Request.Params["etime"].ToString();
           
            string _stime = stime.Replace("-", "").Replace(":", "").Replace(" ", "") + "00";
            string _etime = etime.Replace("-", "").Replace(":", "").Replace(" ", "") + "59";
           

                LightningL19XX list = helper.GetLightningByTime(_stime, _etime, page, pageSize);
                int count = list._Count;
                List<L19XX> lightning = list._L19XX;
                var gridData = new { Rows = lightning, Total = count };
                return Json(gridData);
            
               
        }
View Code

分页(数据库的表结构一致,表名为"L"+年份)

public LightningL19XX GetLightningByTime(string stime, string etime, int page, int pageSize)
        {
            List<L19XX> list = new List<L19XX>();
            int _stime = int.Parse(stime.Substring(0, 4));
            int _etime = int.Parse(etime.Substring(0, 4));
            string _TableName = "L";
            int _count = _etime - _stime;
            string sql = "";
            for (int i = _stime; i <= _etime; i++)
            {
                if (_etime > i)
                {
                    sql += " select * from " + _TableName + i.ToString() + " where L_TIME>=" + stime + " and L_TIME<=" + etime + " union ";
                }
                else
                {
                    sql += " select * from " + _TableName + i.ToString() + " where L_TIME>=" + stime + " and l_TIME<=" + etime + " ";
                }

            }
            int count = entity.Database.SqlQuery<L19XX>(sql).ToList().Count;
            list = entity.Database.SqlQuery<L19XX>(sql).ToList().Skip((page - 1) * pageSize).Take(pageSize).ToList();
            if (list.Count==0)
            {
                L19XX l = new L19XX() { L_ALTITUDE = null, L_CURRENT = null, L_RETIMES = null, L_LONGITUDE = null, L_TIME = null, L_LATITUDE = null, L_ID = null };
                list.Add(l);
            }
            LightningL19XX lightning = new LightningL19XX() { _L19XX = list, _Count = count };
            return lightning;

        }
View Code

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。