我的 JqGrid 从控制器加载数据,但它不显示列表寻呼机。
在这种情况下,LINQ 的查询返回 15 行,但只显示 10 行,无法导航到第二页查看最后 5 行。
我究竟做错了什么??请问,有人可以帮我吗?
看法
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#list2").jqGrid({
url: '@(Url.Action("GetMet", "Meta"))',
datatype: "json",
data: "a",
colNames: ['Id', 'Nome da Loja', 'Mês', 'Ano', 'Meta Monetária', 'Meta Seguro', 'Meta Ticket Médio'],
colModel: [{ name: 'id', index: 'id', width: 20 },
{ name: 'nome', index: 'nome', width: 120, search: true, stype: 'text' },
{ name: 'mes', index: 'mes', width: 40 },
{ name: 'ano', index: 'ano', width: 40 },
{ name: 'metamonetaria', index: 'metamonetaria', width: 90 },
{ name: 'metaseguro', index: 'metaseguro', width: 90 },
{ name: 'metaticketmedio', index: 'metaticketmedio', width: 110 }],
rowNum: 10,
rowList: [10, 20, 30],
pager: '#pager2',
sortname: 'nome',
viewrecords: true,
sortorder: "desc",
caption: 'Metas referente a loja selecionada',
height: 240,
ondblClickRow: function (id) { $("#FUNCIONARIO").val(id); }
});
jQuery("#list2").jqGrid('navGrid', '#pager2', { edit: false, add: false, del: false });
控制器
public JsonResult GetMet(int page = 1, int rows = 10, string sord = "asc", string sidx = "Id")
{
var db = new DataContext().GetGenericRepository();
var totalFunc = db.GetAll<Funcionarios>().Count();
decimal totalPages = 0;
if (totalFunc > 0)
{
totalPages = totalFunc / rows;
totalPages = System.Math.Round(totalPages);
}
else
{
totalPages = 0;
}
if (page > totalPages)
{
page = Convert.ToInt32(totalPages);
}
var result = new
{
total = totalPages,
page = page,
records = totalFunc,
rows = (from metas in db.GetAll<Metas>()
select new
{
id = metas.METAID,
metamonetaria = metas.METAMONETARIA,
metaseguro = metas.METASEGURO,
metaticketmedio = metas.METATICKETMEDIO,
mes = metas.MES,
ano = metas.ANO,
nome = (from lojas in db.GetAll<Lojas>()
where lojas.LOJAID == metas.LOJAID
select lojas.NOME).First()
}).ToArray()
};
return Json(result, JsonRequestBehavior.AllowGet);