【问题标题】:Missing display data in jqGridjqGrid中缺少显示数据
【发布时间】:2017-11-23 18:33:43
【问题描述】:

正如您在下面看到的,我有 3 张图片。 (5, 10 and 20 data per page)。我不知道为什么在10 and 20 per page 中缺少图片所提供的数据。

代码

public JsonResult GetDPS(string sidx, string sord, int page, int rows, string startdate, string enddate, string EmployeeId, string month, string year, int ClassificationId)
    {
        var context = new Entities();
        var _pr = new Repository();
        int _month = Convert.ToInt32(month);
        int _employeeid = Convert.ToInt32(EmployeeId);
        int _year = Convert.ToInt32(year);
        if (_month > 0 && _year > 0)
        {
            DateTime Dstartdate = new DateTime(_year, _month, 1);
            startdate = Dstartdate.AddDays(-1).ToShortDateString();
            enddate = Dstartdate.AddMonths(1).ToShortDateString();
        }
        int pageIndex = Convert.ToInt32(page) - 1;
        int pageSize = rows;
        var periods = _pr.GetDPSList(Convert.ToDateTime(startdate), Convert.ToDateTime(enddate), _employeeid, ClassificationId);
        int totalRecords = periods.Count();
        int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
        var reqs = periods.OrderBy("it." + sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize);
        int i = 0;
        var rowsObj = new object[pageSize > totalRecords ? totalRecords : pageSize];
        foreach (vwDPSPerEmployee req in reqs)
        {
            int rowId = i;
            int DPSHeaderId = Convert.ToInt32(req.DPSHeaderId);
            string DateApplied = req.DateApplied.Value.ToShortDateString();
            string DPSClassification = req.DPSClassificationDesc;
            string StartDate = req.DateFrom.Value.ToShortDateString();
            string EndDate = req.DateTo.Value.ToShortDateString();
            string Departure = req.Departure.Value.ToShortTimeString();
            string Arrival = req.Arrival.Value.ToShortTimeString();
            string Destination = req.Destination;
            string ContactPerson = req.ContactPerson;
            string Purpose = req.Purpose;
            rowsObj[i] = new { id = i, cell = new object[] { rowId, DPSHeaderId, DateApplied, DPSClassification, StartDate, EndDate, DateofDPS, Departure, Arrival, Destination, ContactPerson, Purpose } };
            i++;
        }
        if (totalRecords != 0)
        {
            for (int j = 0; j < rowsObj.Length; j++)
            {
                if (rowsObj[j] == null)
                { rowsObj[j] = new { id = j, cell = new object[] { j, j, "", "" } }; }
                else { }
            }
        }
        var result = new JsonResult();
        result.Data = new
        {
            total = totalPages,
            page = page,
            records = totalRecords,
            rows = rowsObj
        };
        return result;
    }

有人遇到过这样的吗?或者有人知道吗?我花了几天时间来解决这个问题。

【问题讨论】:

  • 请始终写下您使用的 jqGrid 的 version 以及 jqGrid 的哪个 fork(免费 jqGrid、商业 Guriddo jqGrid JS 或旧的 jqGrid版本 Fiddler 之类的工具来获取从服务器返回的 JSON 数据。之后可以创建演示,它在没有服务器的情况下使用数据。

标签: c# jquery asp.net-mvc-3 jqgrid


【解决方案1】:

我认为您应该在 Fileddate(DateApplied) 列上使用排序。

public JsonResult GetDPS(string sidx, string sord, int page, int rows, string startdate, string enddate, string EmployeeId, string month, string year, int ClassificationId)
    {
        var context = new Entities();
        var _pr = new Repository();
        int _month = Convert.ToInt32(month);
        int _employeeid = Convert.ToInt32(EmployeeId);
        int _year = Convert.ToInt32(year);
        if (_month > 0 && _year > 0)
        {
            DateTime Dstartdate = new DateTime(_year, _month, 1);
            startdate = Dstartdate.AddDays(-1).ToShortDateString();
            enddate = Dstartdate.AddMonths(1).ToShortDateString();
        }
        int pageIndex = Convert.ToInt32(page) - 1;
        int pageSize = rows;
        var periods = _pr.GetDPSList(Convert.ToDateTime(startdate), Convert.ToDateTime(enddate), _employeeid, ClassificationId);
        int totalRecords = periods.Count();
        int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
        var reqs = periods.OrderBy(x=>x.DateApplied).Skip(pageIndex * pageSize).Take(pageSize);
        int i = 0;
        var rowsObj = new object[pageSize > totalRecords ? totalRecords : pageSize];
        foreach (vwDPSPerEmployee req in reqs)
        {
            int rowId = i;
            int DPSHeaderId = Convert.ToInt32(req.DPSHeaderId);
            string DateApplied = req.DateApplied.Value.ToShortDateString();
            string DPSClassification = req.DPSClassificationDesc;
            string StartDate = req.DateFrom.Value.ToShortDateString();
            string EndDate = req.DateTo.Value.ToShortDateString();
            string Departure = req.Departure.Value.ToShortTimeString();
            string Arrival = req.Arrival.Value.ToShortTimeString();
            string Destination = req.Destination;
            string ContactPerson = req.ContactPerson;
            string Purpose = req.Purpose;
            rowsObj[i] = new { id = i, cell = new object[] { rowId, DPSHeaderId, DateApplied, DPSClassification, StartDate, EndDate, DateofDPS, Departure, Arrival, Destination, ContactPerson, Purpose } };
            i++;
        }
        if (totalRecords != 0)
        {
            for (int j = 0; j < rowsObj.Length; j++)
            {
                if (rowsObj[j] == null)
                { rowsObj[j] = new { id = j, cell = new object[] { j, j, "", "" } }; }
                else { }
            }
        }
        var result = new JsonResult();
        result.Data = new
        {
            total = totalPages,
            page = page,
            records = totalRecords,
            rows = rowsObj
        };
        return result;
    }

【讨论】:

  • 感谢您的评论。但我已经测试过了。正如我在调试它时注意到的那样。当我不使用断点时,数据将被另一个数据替换。如您所见,8/18/16。但后来我设置断点并打开periods and reqs 的结果并找到数据。它返回得很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-23
  • 1970-01-01
  • 1970-01-01
  • 2016-11-30
相关资源
最近更新 更多