Bala
Bala

Reputation: 1139

JQGrid pagination not working

I am displaying a jqgrid with data which works fine and am trying to implement paging on top of that which is not working. I went through the examples here http://trirand.com/blog/jqgrid/jqgrid.html and tried to implement the same.

This is pretty basic, but I dont know how jqgrid magically implements paging. I am not able to see the paging buttons. I have included the ui.jqgrid.css file too.

inside $(document).ready I call InitializeGrid and completeGrid. Pagination displays records at once. For example, I have given the rowNum as 10, but while displaying it says "View 1-17 of 17". Instead I expect it to display 10 records in the first page and 7 records in the second page.

below is my code.

Code :

function InitializeGrid() { 

    jQuery("#sample").jqGrid({
        datatype: function(postdata) {

        },
        pager: '#gridpager',
        colNames: colNames,
        pgbuttons: true,
        colModel: colModel,
        hoverrows: false,
        hidegrid: false,
        shrinkToFit: true,
        altRows: true,
        scroll: true,
        viewrecords: true,
        footerrow: false,
        gridView: true,
        caption: 'Information',
        loadonce: false,
        sortable: false,
        rowNum: 10,
        cmTemplate: { title: false },
        jsonReader: {
            root: "Data",
            page: "CurrentPage",
            total: "TotalPages",
            records: "TotalRecords",
            repeatitems: false,
            id: "0"
        },
    });
}

function completeGrid(gridData) {
    gridRows = gridData;
    var grid = $("#sample ");
    grid.clearGridData();
    var addRow;
    var gridData = { Data: [], CurrentPage: 1, TotalPages: 1, TotalRecords: 1};
    for (var i = 0; i < gridRows.length; i++) {
        addRow = {
            Group: gridRows[i].Group,
            Member: gridRows[i].Member
        };
        gridData.Data.push(addRow);
    }
    for (var j = 0; j < gridRows.length; j++) {
        jQuery('#sample').addRowData( j, gridData.Data[j]);
    }
}

Upvotes: 0

Views: 9672

Answers (2)

Jai
Jai

Reputation: 74738

What seems to me you have to specify rowList array in the options too:

rowList:[10,20,30],

and try removing the trailing ',' comma from the json reader:

jsonReader: {
        root: "Data",
        page: "CurrentPage",
        total: "TotalPages",
        records: "TotalRecords",
        repeatitems: false,
        id: "0"
    }, // <----------this comma

and if your data is comming dynamically then you have to use

loadOnce: true,

this is required.

Upvotes: 1

sudhansu63
sudhansu63

Reputation: 6180

You need to do pagination while getting data.

Sample code in Asp.net C#

   //Get the page number and page size from query string.
  int iPage = int.Parse(Request.QueryString["page"]);//get the requested page
  int iLimit = int.Parse(Request.QueryString["rows"]); //get how many rows you want to display

  //Taking requires no of records for required page
 //using LINQ query.
  var Res = res.Skip((iPage - 1) * (iLimit)).Take(iLimit).ToList();

Upvotes: 0

Related Questions