我有一个jqgrid的问题。在那个pagecount显示0和页面navaigation不工作..这里我附上了所有相关的代码。
网格数据正在显示,但是从一个页面到另一个页面的页面数量和分页不起作用..我还附加了图像,这对我来说也是输出。
的Javascript
$(document).ready(function () {
$("#grid").jqGrid({
url: '/Home/EmpList',
datatype: "json",
contentType: 'application/json; charset=utf-8',
width: 970,
height: 290,
mtype: 'GET',
colNames: ['Part#', 'Description', 'Application', 'Category', 'Points/$','Valid
Untill'],
colModel: [{ name: 'part_number', index: 'part_number', width: 180 },
{ name: 'description', index: 'description', width: 220 },
{ name: 'pplication', index: 'application', width: 220 },
{ name: 'category', index: 'category', width: 180 },
{ name: 'point_dollar', index: 'point_dollar', width: 180 },
{ name: 'end_date', index: 'end_date', width: 180 }
],
pager: '#pager',
rowNum: 10,
rowList: [10, 20, 30],
sortname: 'part_number',
sortorder: 'desc',
viewrecords: true,
//viewpages: true,
loadonce: true,
gridview: true,
gridComplete: function () {
}
});
});
CSHTML
<link href="~/Content/themes/base/minified/jquery-ui.css" rel="stylesheet" />
<script src="~/Scripts/jquery-ui-1.8.20.min.js"></script>
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />
<link href="~/Content/ui.jqgrid.css" rel="stylesheet" />
<script src="~/Scripts/jquery.jqGrid.src.js"></script>
<script src="~/Scripts/grid.locale-en.js"></script>
<script src="~/Scripts/Parts.js"></script>
<table id="grid" style=" width:970px;"></table>
<table id="pager">
控制器类
[HttpGet]
public JsonResult EmpList()
{
List<Parts> obs = new List<Parts>();
string
cs=Sytem.Web.Configuration.WebConfigurationManager.ConnectionStrings["BMWRewards"].
ConnectionString.ToString();
SqlConnection cn = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "[admin].[usp_parts_list_get]";
cmd.Connection = cn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@oem_id", 2);
cmd.Parameters.AddWithValue("@type", "IRF");
cmd.Parameters.AddWithValue("@category", "ALL");
cmd.Parameters.AddWithValue("@status", "");
cmd.Connection.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Parts obl = new Parts();
obl.part_number=reader["part_number"].ToString();
obl.description=reader["description"].ToString();
obl.application=reader["application"].ToString();
obl.category=reader["part_category_name"].ToString();
obl.point_dollar=float.Parse(reader["point_dollar"].ToString());
obl.end_date=reader["end_date"].ToString();
obs.Add(obl);
}
}
cn.Close();
cmd.Connection.Close();
if (obs.Count() > 0)
{
var pageData = obs;
var jsonData = new
{
total = (int)Math.Ceiling((float)pageData.FirstOrDefault().RowCount /
(float)10),
page = pageData.FirstOrDefault().PageNumber,
records = pageData.FirstOrDefault().PageSize,
rows =
(from rdata in pageData
select new
{
i = rdata.part_number,
cell = new string[] { (rdata.part_number).ToString(),
rdata.description, rdata.application,
rdata.category,rdata.point_dollar.ToString(),rdata.end_date }
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
else
{
var jsonData1 = new
{
total = 0,
page = 1,
records = 0
};
return Json(jsonData1, JsonRequestBehavior.AllowGet);
}
}
答案 0 :(得分:0)
我建议您尝试使用"0"
之类的字符串代替total
,page
和records
属性的整数值,至少在obs.Count() == 0
的情况下:
var jsonData1 = new
{
total = "0",
page = "1",
records = "0"
};
return Json(jsonData1, JsonRequestBehavior.AllowGet);