Search code examples
jqueryjqgridrownum

jqGrid returning only records as defined in rowNum if using loadonce:true


Is this normal or I'm missing something?

If I set loadonce: true, my grid is returning only 5 records.

But if I change it to loadonce: false, the grid is getting all the records

My code is below.

$("#leave-detail-grid").jqGrid({
    url:'grid/grid_leave_detail.php',
    datatype: 'xml',
    mtype: 'GET',
    colNames:['Date','Day','Approver','Leave Type','Status','Purpose | Reason'],
    colModel :[
      {name:'start_date', index:'start_date', width:80, editable:false, align:"left", editrules:{required:true}},
      {name:'day', index:'day', width:80, editable:false, align:"left", editrules:{required:true}},
      {name:'sup', index:'sup', width:130, editable:false, align:"left", editrules:{required:true}},
      {name:'desc', index:'desc', width:130, editable:false, align:"left", editrules:{required:true}},
      {name:'status', index:'status', width:80, editable:false, align:"center", editrules:{required:true}},
      {name:'purpose', index:'purpose', width:180, editable:false, align:"left", editrules:{required:true}}    
    ],
    height: 'auto',
    pager: '#leave-detail-pager',
    pgbuttons: true,
    pginput: 'Yes',
    pgtext: 'Yes',
    rowNum:5,
    rowList:[20,40,100,200,400],
    sortname: 'start_date',
    sortorder: 'asc',
    loadonce: true, // to enable sorting on client side
    viewrecords: true,
    gridview: true,
    caption: 'Search Purpose'
});
$("#leave-detail-grid").jqGrid('navGrid',"#leave-detail-pager",
      {edit:false,add:false,del:false,search:true},
      {zIndex:5234},{zIndex:5234},{zIndex:5234},{zIndex:5234}
);

Solution

  • Thanks Jonathan. How did I miss that demo :)

    I add the colModel rowTotal: 2000, value -1 is not working, this will show 2000 recs

    then add the below to my server code

    $totalrows = isset($_REQUEST['totalrows']) ? $_REQUEST['totalrows']: false;
    if($totalrows) {
    $limit = $totalrows;
    }
    

    And to load all the records we need to tweak the server code to override the rowTotal parameter.

    $result = mysql_query("SELECT COUNT(*) AS count FROM leaveform WHERE emp_id='$emp_id'   AND company_id='$company_id'"); 
    $row = mysql_fetch_array($result,MYSQL_ASSOC); 
    $count = $row['count']; 
    $totalrows =  $count;
    $limit = $totalrows;