Loading Data to grid faster

Hello, I have tried to load 2600 rows to grid.

  1. using connector
    include (“…/…/codebase/connector/grid_connector.php”);
    include (“…/…/codebase/connector/db_pdo.php”);
    $user_data = new GridConnector($dbconn, “PDO”);
    $query = “select nip,nama,alamat from pegawai”;
    $user_data->render_sql($query, “nip”, "nip, nama, alamat ");

  2. using manual way like written on docs
    header ("Content-Type: text/xml; charset=ISO-8859-1 ");
    if( strpos($_SERVER[“HTTP_ACCEPT_ENCODING”],“gzip”) !== FALSE){
    ob_start(“ob_gzhandler”);
    } else {
    ob_start();
    }

     if(isset($_GET["posStart"]))
         $posStart = $_GET['posStart'];
     else
         $posStart = 0;
     if(isset($_GET["count"]))
         $count = $_GET['count'];
     else
         $count = 2600;
    
     $sql = "SELECT nip,nama,alamat FROM pegawai";
    
     if($posStart==0){
         $result = $dbconn->prepare($sql);
         $result->execute();
         $totalCount = $result->rowCount();
     }
    
     $sql.= " LIMIT ".$posStart.",".$count;
    
     $result = $dbconn->prepare($sql);
     $result->execute();
    
     //output data in XML format   
     print("<rows total_count='".$totalCount."' pos='".$posStart."'>");   
     while($row = $result->fetch(PDO::FETCH_ASSOC)) {
         print("<row id='".$row['nip']."'>");
             print("<cell>");
                 print($row['nip']);  //value for column1
             print("</cell>");
             print("<cell>");
                 print($row['nama']);  //value for column2
             print("</cell>");
             print("<cell>");
                 print($row['alamat']);    //value for column3
             print("</cell>");
          print("</row>");
     }
     print("</rows>");
    

    ob_end_flush();

I have tried running these scripts at 2 web hosting, using firebug I got xml file size generated by php :
1.by connector 473kb
2.manual way 79kb (I think this will be faster because xml size smaller)

gzip compression disable by default at web hosting, so I came with this idea using ob_gzhandler

my question : If I want to using ob_start(“ob_gzhandler”) with connector, where I must put this line

Thank you

Note: Attachment image when trying at localhost

You can place the next before render_sql command

function my_output($out){ $text = (string)$out; echo $text; die(); } $user_data->event->attach("beforeOutput", $my_output);

$text here is the output of connector, so you can pre-process and output it as you wish.

Copying your script, I got error:
$user_data->event->attach(“beforeOutput”, $my_output); --> Undefined $my_output
change to:
$user_data->event->attach(“beforeOutput”, my_output); --> Object of class GridConnector could not be converted to string

Sorry, was a typo from my side, the valid code will look like next

function my_output($grid, $out){ $text = (string)$out; echo $text; die(); } $user_data->event->attach("beforeOutput", "my_output");

Thank you Stanislav,
using this method I got file size decreased after placing ob_gzhandler before echo $text, but encounter 2 problems

1.no xml output, if I use this grid.load(“filename.php”) data not going to inside grid, but alerting to messagebox
2. If I want to catch error with putting $user_data->event->attach(“OnDBError”, doOnDBError);
I got Content Encoding Error


You need to output XML header

header("Content-type: text/xml"); //mandatory echo('<?xml version="1.0"?>'); //optional echo $text;

Solved the problem,
but when I placing attach(“OnDBError”, doOnDBError), I got Notice error: Use of undefined constant doOnDBError.

Where I must put attach(“OnDBError”, doOnDBError),
because without attach(“beforeOutput”, “my_output”), the script running properly

function doOnDBError($action, PDOException $ex) {
$error_message = $ex->getMessage();

}

function my_output($grid, $out){
$text = (string)$out;
header ("Content-Type: text/xml; charset=ISO-8859-1 ");
//ob_start(“ob_gzhandler”);
echo $text;
die();
}

$user_data->event->attach("beforeOutput", "my_output");
//$user_data->event->attach("OnDBError", doOnDBError);

You need to use something like next\

[code]function doOnDBError($action, PDOException $ex) {
$error_message = $ex->getMessage();

}

$grid->event->attach(“OnDBError”, “doOnDBError”);[/code]

  • place the method body BEFORE the attach call
  • surround method name in double quotes

Thank you very much Stanislav, I don’t know method name must placed inside double quotes
Because I see without double quotes in this doc
docs.dhtmlx.com/connector__php__ … event.html like this :

function doOnDBError($action, $exception){
$action->set_response_xml("".((String)$exception)."")
}
$conn->event->attach(“onDBError”,doOnDBError);

It is based on the PHP error reporting settings.

With default one it must work with or without double quotes. In your case PHP configure in a bit more strict mode, so it is mandatory to use quotes