title: How to do Paging for jqGrid in Stored Procedure?
body: <p>I'm not good at sql, but I have to do paging for jqGrid in my stored procedure which has many records. My asp.net mvc3 controller code as follows,</p>
  
  <pre><code>[HttpPost]
      public JsonResult GetExtraPersons(int cId, long pId, JQGridSettings gridSettings)
      {
          List&lt;ExtraPerson&gt; extraPersons = new List&lt;ExtraPerson&gt;();            
          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 =&gt; 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);
      }
  </code></pre>
  
  <p>as well as my stored procedure in sql server 2008 as follows,</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Now jqGrid is working properly except paging. For ex: If it has 15 records, the first page shows 10 records, remaining is in second page but I cant go to it.
  Can anyone suggest me, how to do paging for jqgrid?</p>