DataGrid - Important Syntax Changes in new versions >= 7.x.x

Discuss everything related to ApPHP DataGrid class. All versions. Any questions related to the ApPHP DataGrid developing or using should be posted to this forum.
Please, check out Knowledge Base first before you post a question.

Moderator: alexandrleonenko

Forum rules
Posts are to be made in the relevant forum. Users are asked to read the forum descriptions before posting.
administrator
Site Admin
Site Admin
Posts: 6001
Joined: Jan 7th, '09, 23:18
Contact:

DataGrid - Important Syntax Changes in new versions >= 7.x.x

Postby administrator » Oct 27th, '11, 09:49

There are some important changes in version 7.x.x
Please this post carefully.
Generally the component still supports old syntax, but we strongly recommend to start using of new syntax.


1. From now DataGrid supports PDO extension, so there are some changes in DataGrid object creating
Using the PDO can reduce execution time by 3-4 times!

OLD Syntax:

Code: Select all

define ("DATAGRID_DIR", "");                     /* Ex.: "datagrid/" */
define ("PEAR_DIR", "pear/");                    /* Ex.: "datagrid/pear/" */
require_once(DATAGRID_DIR.'datagrid.class.php');
require_once(PEAR_DIR.'PEAR.php');
require_once(PEAR_DIR.'DB.php');

$DB_USER='name';           
$DB_PASS='';                     
$DB_HOST='localhost';       
$DB_NAME='dbName';       

$db_conn = DB::factory('mysql');  /* don't forget to change on appropriate db type */
$result_conn = $db_conn->connect(DB::parseDSN('mysql://'.$DB_USER.':'.$DB_PASS.'@'.$DB_HOST.'/'.$DB_NAME));
if(DB::isError($result_conn)){ die($result_conn->getDebugInfo()); }

##  *** set needed options and create a new class instance
$debug_mode = false;   
$messaging = true;       
$unique_prefix = "abc_";
$dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);

##  *** set data source with needed options
$sql = "SELECT primary_key, field_1, field_2 ... FROM tableName ;";

$default_order = array();   /* Ex.: array("field_1"=>"ASC", "field_2"=>"DESC") */
$dgrid->DataSource($db_conn, $sql, $default_order);   


NEW Syntax:

Code: Select all

define ("DATAGRID_DIR", "");                     /* Ex.: "datagrid/" */
require_once(DATAGRID_DIR.'datagrid.class.php');

##  *** set needed options and create a new class instance
$debug_mode = false;   
$messaging = true;       
$unique_prefix = "abc_";
$dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix);

##  *** first parameter "PEAR" or "PDO" (experimental)
$DB_USER='name';     
$DB_PASS='';             
$DB_HOST='localhost';
$DB_NAME='dbName';

$sql = "SELECT primary_key, field_1, field_2 ... FROM tableName ;";
$default_order = array();   /* Ex.: array("field_1"=>"ASC", "field_2"=>"DESC") */
$dgrid->DataSource("PEAR", "mysql", $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS, $sql, $default_order);


3. Changes in DataGrid constructor:
we don't pass now DATAGRID_DIR as a 4th parameter in costructor.

OLD Syntax:

Code: Select all

$dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix, DATAGRID_DIR);


NEW Syntax:

Code: Select all

$dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix);


2. Changes in default order fileds:
now it's an array and not two parameters.

OLD Syntax:

Code: Select all

$default_order_field = "field_name_1"; /* Ex.: field_name_1 [, field_name_2...] */
$default_order_type = "ASC";           /* Ex.: ASC|DESC [, ASC|DESC...] */

NEW Syntax:

Code: Select all

$default_order = array();   /* Ex.: array("field_1"=>"ASC", "field_2"=>"DESC") */


4. Changes in exporting feature syntax:
Below the new syntax.

Code: Select all

## +-- Exporting --------------------------------------------------------------+
##  *** initialize the session with session_start();
##  *** default exporting directory: tmp/export/
$exporting_option = true;
$export_all = false;
$dgrid->AllowExporting($exporting_option, $export_all);
$exporting_types = array('csv'=>'true', 'xls'=>'true', 'pdf'=>'true', 'xml'=>'true');
$dgrid->AllowExportingTypes($exporting_types);


5. If you still use old syntax:
PEAR directory was moved to the modules directory and it's full path now is following:
modules/pear/

Return to “ApPHP DataGrid”