Check documentation for the latest version of dhtmlxSuite Data Loading HowTos DHTMLX Docs

Data Loading HowTos

How can I call a stored procedure?

To load data with a stored procedure, you should use the render_complex_sql method.

$grid->render_complex_sql("exec usp_findusers 'John'","id",
"name,surname,age,address,phone");

How can I enable dynamic loading?

To enable dynamic loading you should:

  • on the client side enable the related mode (e.g. smart rendering or paging for grid)
grid.enableSmartRendering(mode,buffer);
$grid->dynamic_loading([$rowsNum]);

See the guide 'Dynamic loading' for more information.

How can I format/change data before loading?

To set some specific formatting or change data before sending to the client side, you should use the beforeRender event handler. For more details on this topic, see the 'Formatting/Changing Data before Loading' chapter.

function color_rows($row){
    if ($row->get_index()%2)
    $row->set_row_color("red");
}
 
$grid->event->attach("beforeRender","color_rows");

How can I get the loaded data?

To get the data generated by dhtmlxConnector on the server side, call the asString command with the true parameter and the related 'render' method:

$conn = new GridConnector($res,"MySQL");
$conn->asString(true);
 
$result = $conn->render_table("tevents","event_id","text,start_date,end_date");

For more info on this topic, read the chapter 'Returning data as a string' in 'Basic loading' guide.

How can I join tables?

See the details in the related chapter of documentation: "Joining tables".

How can I load data from a database table?

To load data from a database table you should use one of two methods:

$grid->render_table("tableA","item_id","column1,column2", "extra_column3");
$grid->render_sql(
    "Select * from tableA, tableB  where  tableA.id=tableB.id", 
    "tableA.id","column1,column2"
);

How can I load data from Excel file?

To load data from Excel file you should download phpExcel library from https://dhtmlx.com/docs/technical-support.shtml and include additional files:

  • 'lib/PHPExcel.php' (phpExcel package)
  • 'lib/PHPExcel/IOFactory.php' (phpExcel package)
  • 'db_excel.php' (standard connector's package)

Then, call the render_table() method where as parameters you should specify the cell range and Excel columns. Set the second parameter to 'id' for auto id generation.

//files from phpExcel package
require_once('lib/PHPExcel.php');
require_once('lib/PHPExcel/IOFactory.php');
//connectors
require("../../codebase/db_excel.php");
require("../../codebase/grid_connector.php");
 
$grid = new GridConnector("../some.xls", "ExcelDBDataWrapper");
$grid->render_table("A18:F83", "id", "A,B,C,D,E,F");

For more details see the chapter 'Loading from Excel file' in 'Basic loading' guide.

How can I load data from File System?

To load data from File System you should include an additional file - db_filesystem.php and call the render_table() method where as parameters you should specify folder (that requires data listing), field's id (leave it empty or use safe_name as ID of file) and lists of fields.

require("./codebase/connector/db_filesystem.php");
require("./codebase/connector/grid_connector.php");
 
$grid = new GridConnector("", "FileSystem");
$grid->render_table(
    "../",
    "safe_name",
    "filename,full_filename,size,name,extention,date,is_folder"
);

For more details, see the guide chapter 'Loading from File System' in 'Basic loading' guide.

How can I load data from PHP array?

To load data from a PHP array you should use the method render_array

$data = array(
    array("id" => "1", "product" => "Phone AB12",    price => "460"),
    array("id" => "2", "product" => "Tablet device", price => "830")
);
$conn->render_array($data, "id", "product,price");

For more details, see the chapter 'Loading from PHP array' in the 'Basic loading' guide.

How can I load data from several connectors in one request?

To combine data configured by several connectors and return it in one request you should use MixedConnector.

$data1 = new JSONDataConnector($res);
$data1->configure("country_data", "country_id", "name,full_name,type");
 
$data2 = new JSONTreeDataConnector($res);
$data2->configure("tasks_data","taskId","taskName","","parentId");
 
$conn = new MixedConnector($res);
$conn->add("countries", $data1);
$conn->add("tasks", $data2);
$conn->render(); //retrieves configured data from the server

See details in the article 'Mixed connector'.

How can I send additional information to the client side?

In order to send to the client side additional information that won't be outputted but you'll have access to, use the fourth(optional) parameter of the render_table() method. There you should specify columns that contain the desired additional information.

$grid->render_table("some_table","id","name,price","color,count");

For more information see the chapter 'Using extra fields' in the 'Formatting/Changing Data before Loading' guide.

How can I set userdata?

To set userdata you should use the set_userdata method:

function formatting($row){
    $row->set_row_color($row->get_value("color"));
    $row->set_userdata("some_data",$row->get_value("count"));
}
Back to top