Click here to Skip to main content
15,881,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can someone help me with this issue?
I have a jqgrid(4.4.0) and I want to implement true scrolling. The problem is that it only loads datarows once, meaning the first page only. So when I scroll, it doesn't fetch the other pages. I have checked this link and still not working.

Here is the jqgrid:

JavaScript
jQuery("#deptProjectsGrid").jqGrid({
            url: '@Url.Action("GetUserProjects", "TimesheetByWeek")',
            datatype: 'json',
            mtype: 'GET',
            colNames: ['Projekt', 'Oprettet af'],
            colModel: [
                        { name: 'project', index: 'project', sortable: true, align: 'left' },
                        { name: 'creator', index: 'creator', align: 'left' }
                      ],
            height: 300,
            width: 250,
            altRows: true,
            pager: '#pager1',
            scroll: 1,
            rowNum: 15,
            rownumbers: true,
            viewrecords: true,
            sortname: 'project',
            sortorder: 'desc',
            gridview: true,
            caption: "Projekter",
            onSelectRow: function (ids) {
                if (ids == null) {
                    ids = 0;
                    if ($taskgrid.jqGrid('getGridParam', 'records') > 0) {
                        $taskgrid.jqGrid('setGridParam', { url: '@Url.Action("GetProjectTasks", "TimesheetByWeek")/' + ids });
                        $taskgrid.jqGrid('setCaption', "No Tasks " + ids).trigger('reloadGrid');
                    }
                } else {
                    var data = $("#deptProjectsGrid").getRowData(ids);
                    $taskgrid.jqGrid('setGridParam', { url: '@Url.Action("GetProjectTasks", "TimesheetByWeek")/' + ids });
                    $taskgrid.jqGrid('setCaption', "Tasks for " + data.project).trigger('reloadGrid');
                }
            }
        });

The controller action looks like this:

C#
public JsonResult GetUserProjects(int page, int rows, string search, string sidx, string sord)
        {
            try
            {
                using (DanishEntities db = new DanishEntities()) 
                {
                    
                    int totalRecords = 0;
                    var allProjectEntities = _projectRepository.GetProjectsPaged(page, rows, out totalRecords, db);
                    var projects = Mapper.Map<List<Project>, List<ProjectModel>>(allProjectEntities);

                    var totalPages = (int)Math.Ceiling(totalRecords / (float)rows);
                    var jsonData = new
                    {
                        total = rows,
                        page = page++,
                        records = totalRecords,
                        rows = (
                                   from p in projects
                                   select new
                                   {
                                       id = p.ID,
                                       cell = new object[] { p.Name, "john doe" }
                                   }).ToArray()
                    };
                    return Json(jsonData, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception)
            {

                throw;
            }
        }

and the query is:

C#
public List<Project> GetProjectsPaged(int page, int rows, out int totalCount, DanishEntities dbContext)
        {
            List<Project> pagedProjectEntities = new List<Project>();
            try
            {

                totalCount = dbContext.Projects.Count();
                pagedProjectEntities = dbContext.Projects
                        .OrderBy(p => p.ID)
                        .Skip((page-1) * rows)
                        .Take(rows)
                        .ToList();

            }
            catch (Exception)
            {
                throw;
            }

            return pagedProjectEntities;
        }

I have wasted 4 hours of my life trying to figure this out and I just can't see the problem. I have even set "total = totalPages" in the controller action but nothing is working. Help please!!
Just another quick question on jqGrid: How do I disable "rowNum" in a jqGrid so that the grid shows all available rows returned by the query in the data set?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900