1

I am new to JQGrid. Let me explain the issue I am facing ...

I am using struts2-jquery grid, which is internally using JQGrid, and am controlling the grid outside, example: I am using search elements to filter rows in the grid.

When ever the grid is loading, the pager works fine, but when am filtering data the pager is not working and it shows some infinite values . Can any one out there tell me solution for this, since I can't post my code also ... If I got any working example for the above issue is really appreciable ...

Raidri
  • 17,258
  • 9
  • 62
  • 65
Esh
  • 836
  • 5
  • 16
  • 43

1 Answers1

1

Not seeing any code makes things a bit difficult. But here is the code I used in one of my projects to implement pagination in a project that used JQgrid (see if it helps you out in anyway, or an indication on where to start debugging)

Server side code

public ActionResult GridData(int page, int rows, string searchField = "", string searchString = "",
                                     string searchOper = "", string sidx = "ID", string sord = "desc")
        {          
            int pageIndex = Convert.ToInt32(page) - 1;
            int pageSize = rows;

            var items = _repo.GetItemDatacollection(searchField, searchString, searchOper, pageIndex, pageSize, sidx, sord);

            int totalRecords = _repo.GetAll().Count();
            var totalPages = (int)Math.Ceiling(totalRecords / (float)pageSize);

            var jsonData = new
            {
                total = totalPages,
                page,
                records = totalRecords,
                rows = (from item in items.ToList()
                        select new
                        {
                            i = item.ID,
                            cell = new[] { item.ID, item.Name }
                        }).ToArray()
            };
            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }

GetItemDataCollection basically does something like this. (I made use of Scott Guthrie's dynamic LINQ library inside it, which was very useful, if not pivotal for implementing searching in JQgrid using a LINQ)

  return _entities.Set<T>().Where(ConvertOpr(searchOper, searchField), searchString)
                                      .OrderBy(sidx + " " + sord)
                                      .Skip(pageIndex * pageSize)
                                      .Take(pageSize);

JQgrid implementation

 jQuery('#theGrid').jqGrid({
            url: '@Url.Action("GridData")',
            datatype: 'json',
            mtype: 'GET',
           //...
 });
Rohan Büchner
  • 5,333
  • 4
  • 62
  • 106
  • thanks a lot .... i got the answer few days ago ... i also used the same approach of your ..... – Esh Sep 06 '12 at 04:19