jqGrid Taking Long Time For Large Records

后端 未结 2 1230
迷失自我
迷失自我 2020-12-17 04:29

I am using jgGrid. Its working perfectly but when i pass about 90,000 records and open the page in google chrome it takes around 8 sec to create a grid which in my case it s

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 05:07

    Try loading JqGrid as on demand, i.e load smaller chunk of data at one time instead of all data and load remaining data on pagination.

    Here is a sample code for reference

    PHP with MySQL

    ...
    $page = $_GET['page']; // get the requested page
    
    $limit = $_GET['rows']; // get how many rows we want to have into the grid
    
    $sidx = $_GET['sidx']; // get index row - i.e. user click to sort
    
    $sord = $_GET['sord']; // get the direction
    
    if(!$sidx) $sidx =1;
    
    // connect to the database    
    $db = mysql_connect($dbhost, $dbuser, $dbpassword)
    or die("Connection Error: " . mysql_error());    
    
    mysql_select_db($database) or die("Error conecting to db.");
    
    $result = mysql_query("SELECT COUNT(*) AS count FROM invheader a, clients b WHERE a.client_id=b.client_id");
    
    $row = mysql_fetch_array($result,MYSQL_ASSOC);
    
    $count = $row['count'];    
    
    if( $count >0 ) {
        $total_pages = ceil($count/$limit);
    } else {
        $total_pages = 0;    
    }
    
    if ($page > $total_pages) $page=$total_pages;
    
    $start = $limit*$page - $limit; // do not put $limit*($page - 1)
    
    if ($start<0) $start = 0;
    
    $SQL = "SELECT a.id, a.invdate, b.name, a.amount,a.tax,a.total,a.note FROM invheader a, clients b WHERE a.client_id=b.client_id ORDER BY $sidx $sord LIMIT $start , $limit";
    
    $result = mysql_query( $SQL ) or die("Couldnt execute query.".mysql_error());
    
    $responce->page = $page;
    
    $responce->total = $total_pages;
    
    $responce->records = $count;
    
    $i=0;
    
    while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
    
        $responce->rows[$i]=$responce->rows[$i]['cell']=array($row[id],$row[invdate],$row[name],$row[amount],$row[tax],$row[total],$row[note]);
    
        $i++;
    } 
    
    echo $json->encode($responce); // coment if php 5
    //echo json_encode($responce);
    ...
    

提交回复
热议问题