我是jqgrid的首发,我为create和fill jqgrid编写了这段代码(我在asp.net中使用了存储库pattrn)
namespace Clearance.Helper
{
using System;
public class JQGridRow
{
public int id;
public string[] cell;
}
}
namespace Clearance.Helper
{
public class JQGridResults
{
public int Page { get; set; }
public int Total { get; set; }
public int Records { get; set; }
public JQGridRow[] rows;
}
}
namespace Clearance.Business
{
using System;
using System.Linq;
using Model;
using Clearance.Repository;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using Clearance.Helper;
public class TransportTypesBusiness : GenericBusiness<CLEARANCEEntities, TRANSPORT_TYPES>
{
public List<TRANSPORT_TYPES> GetAll(int pageSize, int pageIndex)
{
var repository = new TransportTypesRepository(this.Context);
return (List<TRANSPORT_TYPES>) repository.GetAll().OrderBy(c => c.TRANSPORT_ID).Skip(pageIndex * pageSize).Take(pageSize);
}
public string BuildJQGridResults(int numberOfRows = 0, int pageIndex = 0, int totalRecords = 0)
{
var result = new JQGridResults();
var rows = new List<JQGridRow>();
var list = GetAll(numberOfRows, pageIndex);
int li = list.Count();
totalRecords = list.Count();
foreach (var item in list)
{
var row = new JQGridRow { id = item.TRANSPORT_ID, cell = new string[4] };
row.cell[0] = item.TRANSPORT_ID.ToString();
row.cell[1] = item.TRANSPORT_NAME;
row.cell[2] = item.TRANSPORT_ABBR;
row.cell[3] = item.REMARK;
rows.Add(row);
}
result.rows = rows.ToArray();
if ((numberOfRows != 0) && (pageIndex != 0) && (totalRecords != 0))
{
result.Page = pageIndex;
result.Total = (totalRecords + numberOfRows - 1) / numberOfRows;
result.Records = totalRecords;
}
return new JavaScriptSerializer().Serialize(result);
}
}}
和js代码
$(function () {
var grid = $('#list');
grid.jqGrid({
url: 'jQGridHandler.ashx',
editurl: 'jQGridHandler.ashx',
postData: { ActionPage: 'TransportType', Action: 'Fill' },
ajaxGridOptions: { cache: false },
datatype: 'json',
height: 'auto',
colNames: ['TRANSPORT_ID', 'TRANSPORT_NAME', 'TRANSPORT_ABBR', 'REMARK'],
colModel: [
{ name: 'TRANSPORT_ID', index: 'TRANSPORT_ID', key: true, hidden: true, editable: false },
{ name: 'TRANSPORT_NAME', width: 200, sortable: true, editable: true },
{ name: 'TRANSPORT_ABBR', width: 100, sortable: true, editable: true },
{ name: 'REMARK', width: 100, sortable: true, editable: true }
],
rowNum: 10,
rowList: [10, 20, 30],
pager: '#pager',
prmNames: { nd: null },
gridview: true,
sortname: 'TRANSPORT_ID',
viewrecords: true,
caption: '',
rownumbers: true
});
当jqgrid加载数据集当前页面为0并且图标接下来并启用privice时。请帮我。谢谢所有
答案 0 :(得分:1)
页码问题很容易解决。类JQGridResults
包含属性Page
,Total
,Records
和rows
,但jqGrid等待的默认名称为page
,{{1 },total
和records
。因此rows
是唯一可以正确读取的属性。
要解决此问题,您可以在rows
中重命名该属性,或在jqGrid中包含以下附加参数:
JQGridResults
有关jqGrid的使用以及您可以在demo project中找到的ASHX处理程序的更多其他信息(包括完整的Visual Studio the answer)。