我不擅长 sql,但我必须在我的存储过程中为 jqGrid 进行分页,该存储过程有很多记录。我的asp.net mvc3控制器代码如下,
[HttpPost]
public JsonResult GetExtraPersons(int cId, long pId, JQGridSettings gridSettings)
{
List<ExtraPerson> extraPersons = new List<ExtraPerson>();
ExtraPersonViewModel extraPersonViewModel = new ExtraPersonViewModel();
extraPersonViewModel.CampId = cId;
extraPersonViewModel.ReferencePatientId = pId;
extraPersons = ExtraPersonService.GetExtraPersons(extraPersonViewModel.CampId, extraPersonViewModel.ReferencePatientId);
int pageIndex = gridSettings.pageIndex;
int pageSize = gridSettings.pageSize;
int totalRecords = extraPersons.Count;
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
int startRow = (pageIndex - 1) * pageSize;
int endRow = startRow + pageSize;
var jsonData = new
{
total = totalPages,
page = pageIndex,
records = totalRecords,
rows =
(
extraPersons.Select(e => new
{
Id = e.ExtraPersonId,
FirstName = e.FirstName,
LastName = e.LastName,
MobilePhone = e.MobileNumber,
Email = e.EmailId,
PersonalNumber = e.PersonNumber,
Diabetes = e.Diabetes,
BloodPressure = e.BloodPressure,
})
).ToArray()
};
return Json(jsonData);
}
以及我在 sql server 2008 中的存储过程如下,
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[GetExtraPerson]
(
@CampId INT,
@ReferencePatientId BIGINT
)
AS
BEGIN
SET NOCOUNT ON
SELECT
PERS.PersonId,
PERS.FirstName,
PERS.LastName,
PERS.MobileNumber,
PERS.EmailId,
PERS.PersonNumber,
E.ExtraPersonId,
E.Diabetes,
E.BloodPressure
FROM
ExtraPerson E
INNER JOIN Person PERS
ON PERS.PersonId=E.PersonId
WHERE E.CampId=@CampId AND ReferencePatientId=@ReferencePatientId AND E.IsDeleted = 0
END
现在 jqGrid 工作正常,除了分页。例如:如果它有 15 条记录,第一页显示 10 条记录,其余在第二页但我不能去。谁能建议我,如何为 jqgrid 进行分页?