Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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}
);
like image 954
genpet Avatar asked Jan 28 '12 15:01

genpet


2 Answers

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;
like image 191
genpet Avatar answered Oct 13 '22 03:10

genpet


rowNum:5, means that the grid will only use 5 rows.

loadonce: true means that it will only load once. It also disables the pager.

Based on this configuration, that grid will only use 5 rows, and since it will not load anymore from the server, it will always be the same 5.

Here a link to the Wiki which has the latest options documentation: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options

like image 38
Jonathan Avatar answered Oct 13 '22 01:10

Jonathan