dhtmlxconnector:data_management_how-tos_loading [DHX documentation]

PHP Connector DHTMLX

Data management how-tos (loading data)

How can I enable dynamic loading?

To enable dynamic loading you should:

  • on client-side enable the related mode (e.g. smart rendering or paging for grid)

    grid.enableSmartRendering(mode,buffer);
  • on server-side call method dynamic_loading()

    $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 client-side, you should use the beforeRender event handler. For more details of this topic, see 'Formatting/Changing Data before Loading'

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

How can I load data from database table?

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

  • render_table() (for loading from single table)

    $grid->render_table("tableA","item_id","column1,column2", "extra_column3");
  • render_sql() (for loading from several tables)

    $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 http://support.dhtmlx.com/x-files/connector/phpExcel.zip and include additional files:

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

Then, call render_table()) method where as parameters you should specify 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 guide chapter 'loading from Excel file' in 'Base concepts' guide.

How can I load data from File System?

To load data from File System you should include one additional file db_filesystem.php and call 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 'Base concepts' guide.

How can I send additional information to client-side?

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

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

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