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");
To enable dynamic loading you should:
grid.enableSmartRendering(mode,buffer);
$grid->dynamic_loading([$rowsNum]);
See the guide 'Dynamic loading' for more information.
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");
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.
See the details in the related chapter of documentation: "Joining tables".
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"
);
To load data from Excel file you should download phpExcel library from https://dhtmlx.com/docs/technical-support.shtml and include additional files:
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.
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.
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.
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'.
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.
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