【发布时间】: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