0

I'm looking for a way to have jqgrid default to the last page of the grid on page load. I want the sort order to stay ascending and the last page of the grid to come up first. I'm using something like this:

$(function(){ 
  $("#list").jqGrid({
    url:'visitors.php',
    datatype: 'xml',
    mtype: 'GET',
    colNames:['timestamp', 'user','last_visit','last_purchase','purchase_amount'],
    colModel : gridColModel,
    pager: '#pager',
    rowNum:20,
    rowList:[10,20,30],
    sortname: 'timestamp',
    sortorder: 'asc',
    viewrecords: true,
    gridview: true,
    autowidth: true,
    editurl: 'edit.php',
  })
  .navGrid('#pager',{edit:false,add:false,del:false,search:false}) 
});
keitwirik
  • 1
  • 1
  • 3

2 Answers2

0

I actually figured out how to do this without loading the grid and then loading the last page (so you only load the grid once).

When you init your jqGrid you need to do:

$('#list').jqGrid({
    ...
    page: 'last'
    ...
});

That will send a page=last on the initial load of the data. So inside of my data request method (server side) I have the following:

        if (page == "last")
        {
            iPage = (int)Math.Ceiling(results.Count/(double)rows);
        }

Now you know what the last page will be, and can skip the proper number of rows:

results.Skip(rows * (iPage - 1)).Take(rows)

As I'm using json and not XML, I then go on to return the typical structure (rows, page, total pages, total records) as json.

sdm350
  • 397
  • 1
  • 6
  • 17
0

It seems it is already answered in moving to other page programmatically

Hope this can be used in your case.

Community
  • 1
  • 1
Sasidhar Vanga
  • 3,384
  • 2
  • 26
  • 47
  • Thanks Vanga, that does solve my problem if I programmatically click the id of the 'last' button. I was hoping for a default option so I wouldn't have to reload the grid, but that works for me. – keitwirik Feb 18 '12 at 09:07