Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: JQGrid
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:
 
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:
 
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:
 
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 11-Sep-12 1:13am

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

  Print Answers RSS
0 OriginalGriff 319
1 Kornfeld Eliyahu Peter 265
2 Maciej Los 249
3 BillWoodruff 205
4 Sergey Alexandrovich Kryukov 175
0 OriginalGriff 5,107
1 DamithSL 4,157
2 Maciej Los 3,595
3 Kornfeld Eliyahu Peter 3,450
4 Sergey Alexandrovich Kryukov 2,741


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 11 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100