Getting Started with ApPHP DataGrid (for v7.0.0 or above)



Common Notices

Syntax.


We use
## for comments
// for lines, that must be uncommented
/// for lines, that may be uncommented (optional)


Common notes.


Please, use a $debug_mode = true; before you say "Why Nothing Works ?!"
Starting with version 5.0.0 only PHP5 is supported!
Do not put DataGrid code into another HTML form: <form>...</form>
Be careful when using the names of fields they may be case sensitive.
For the best performance use ob_start(); before and ob_end_flush(); after DataGrid code.



Getting Started

Step 1. Creating & Calling.


Be sure you write here a right relative (virtual) path to the datagrid.class.php file and pear directory (relatively to the current file).
RELATIVE PATH ONLY
/* Ex.: "datagrid/" or "../datagrid/" */
define('DATAGRID_DIR', '');    
require_once(DATAGRID_DIR.'datagrid.class.php');
Assign proper values for these variables. Be sure, you use a prefix if you need it.
## *** creating variables that we need for database connection 
$DB_USER='user_username'; /* usually like this: prefix_name           */
$DB_PASS='user_password'; /* don't use empty passwords (recommended)  */
$DB_HOST='localhost';     /* usually localhost                        */
$DB_NAME='db_name';       /* usually like this: prefix_dbName         */
Create the a new instance of class and link the DataGrid class to our database. We can add a unique prefix (optional) to our datagrid if we want to prevent using of double names on this page (in case, when you use some datagrids or forms on same page).
## *** set all needed options and create a new instance of class 
// display SQL statements while processing 
$debug_mode = false;
// display system messages on a screen     
$messaging = true;
// prevent overlays - must be started with a letter
$unique_prefix = 'abc_';

$dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix);
We need to prepare the SELECT SQL statement for View Mode. It can be any type of SELECT statement your database supports (with JOIN, UNION etc.), but you must put the primary key on the first place. Also be careful to write all fields you need them to be shown, because the DataGrid class works with only on fields that you placed in SELECT statement.
Don't add here ORDER BY, LIMIT words or ; at the end of the statement.
PRIMARY KEY MUST BE AUTO-INCREMENT NUMERIC!
## *** put a primary key on the first place 
$sql = 'SELECT primary_key, filed_1, filed_2 ... FROM tableName ';
Now we need to set data source to the DataGrid. We may define default columns ordering, by writing an appropriate fields in $default_order array (you can write some fields) and a sorting type.
Example #1: $default_order = array('Region'=>'ASC', 'CountryID'=>'DESC');
Example #2: $default_order = array('right(Region,1)'=>'ASC', 'Country'=>'DESC');
## *** set data source with needed options
// make default(first) ordering by this field
$default_order = array();
// first parameter 'PEAR' or 'PDO' (default)
$dgrid->DataSource('PDO', 'mysql', $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS, $sql, $default_order);



Step 2. General Settings.


If you want to enable GET, POST or AJAX postback methods you have use following feature.
## *** defines postback method for DataGrid: AJAX, POST(default) or GET
$postback_method = 'post';
$dgrid->SetPostBackMethod($postback_method);
If you want to enable using of smart caching - you have to turn on this feature.
## *** make sure your tmp/cache/ dir has 755 (write) permissions
## *** parameters: 1st - allow caching, 2nd - cache lifetime in minutes
$dgrid->SetCachingParameters(true, 5);
## *** delete all caching pages
/// $dgrid->DeleteCache();
If you want to use a local language (not English) - you have to set the right encoding. The database, tables and appropriate fields in your database must be created with the same CHARACTER SET and COLLATE too. Also you need to define in your file: header('Content-type: text/html; charset=XXXX'); where xxxx ISO-8859-1 or UTF-8 or whatever you have.
Example: CHARSET=utf8 COLLATE=utf8_unicode_ci
Example: <meta http-equiv=Content-Type content="text/html; charset=UTF-8">
## *** set encoding (default - utf8)
$dg_encoding = 'utf8'; 
$dgrid->SetEncoding($dg_encoding);
Set interface language for DataGrid (en - default). All supported languages are listed under commented lines.
## *** set interface language (default - English)
## *** (ar) - Arabic     (bg) - Bulgarian      (ca) - Catala
## *** (ch) - Chinese    (cz) - Czech          (da) - Danish
## *** (de) - German     (en) - English        (es) - Espanol
## *** (fi) - Finnish, Suomi   (fr) - Francais (gk) - Greek     
## *** (he) - Hebrew     (hr) - Bosnian/Croatian (hu) - Hungarian
## *** (it) - Italian    (ja) - Japanese       (ko) - Korean 
## *** (lt) - Lithuanian (nl) - Netherlands/"Vlaams"(Flemish)    
## *** (pl) - Polish     (pb) - Brazilian Portuguese             
## *** (ro) - Romanian   (ru) - Russian        (sv) - Swedish        
## *** (sr) - Serbian    (th) - Thai           (tr) - Turkish
## *** (pt) - Portuguese
$dg_language = 'en';  
$dgrid->SetInterfaceLang($dg_language);
Option for some right-to-left languages (Hebrew, Arabic etc.)
## *** set direction: "ltr" or "rtl" (default - ltr)
$direction = 'ltr';
$dgrid->SetDirection($direction);
Set layouts for datagrid in view or edit mode and for the filtering block.
Attention: use 'view'=>0, 'edit'=>0 only for cases when order of fields is the same both in view and edit modes !!!
For Details Mode there are only 2 types of layouts: '1' or '2'
## *** datagrid layouts: '0' - tabular(horizontal) - default, '1' - columnar(vertical), '2' - customized
## *** use 'view'=>'0' and "edit"=>"0" only if you work on the same tables
## *** filter layouts: '0' - tabular(horizontal) - default, '1' - columnar(vertical), '2' - advanced(inline)
$layouts = array('view'=>0, 'edit'=>1, 'filter'=>1); 
$dgrid->SetLayouts($layouts);
Set templates for datagrid in view/edit or detail modes.
{field_name_1}|{field_name_2} etc. - will be replaced with appropriate field
@field_name_1@|@field_name_2@ - will be replaced with column header that allows sorting
[ADD],[CREATE],[EDIT],[DELETE],[BACK],[CANCEL],[UPDATE],[MULTIROW_CHECKBOX] or [ROWS_NUMERATION] - allowed elements and operations (must be placed in $template['body'] only)
$view_mode_template = array('header'=>'', 'body'=>'', 'footer'=>'');
$edit_mode_template = array('header'=>'', 'body'=>'', 'footer'=>'');
$details_template = array('header'=>'', 'body'=>'', 'footer'=>'');
$details_template['body'] = '<table><tr><td>{field_name_1}</td><td>{field_name_2}</td></tr></table>';
$details_template['footer'] = 'html here...';
$dgrid->SetTemplates($view_mode_template, $edit_mode_template, $details_template);
Set various modes for datagrid. true - allow the operation in this mode('view' or 'edit'), false - don't allow. type - a type of command button (link, html button or image). byFieldValue - if you want to make this field to be a link to edit mode page (instead of edit button), write here a name of the field. If you want to use a standart edit command button leave this parameter empty: 'byFieldValue'=>''
## *** set modes for operations ('type' = 'link|button|image'),
## *** 'view' - view mode | 'edit' - add/edit/details modes
## *** ('byFieldValue' - make the field as a link to edit mode page)
## *** 'show_button' - specifies to show mode button or not
$modes = array(
  'add' => array('view'=>true, 'edit'=>false, 'type'=>'link', 'show_button'=>true, 'show_add_button'=>'inside|outside'),
  'edit' => array('view'=>true, 'edit'=>true, 'type'=>'link', 'show_button'=>true, 'byFieldValue'=>''),
  'details' => array('view'=>true, 'edit'=>false, 'type'=>'link', 'show_button'=>true),
  'delete' => array('view'=>true, 'edit'=>true, 'type'=>'image', 'show_button'=>true)
);
$dgrid->SetModes($modes);
Set scrolling settings and parameters for DataGrid. If you want the DataGrid will be displayed with scrolling, allow this option by the next commands.
## *** allow scrolling on datagrid
$scrolling_option = false;
$dgrid->AllowScrollingSettings($scrolling_option);

## *** set scrolling settings (optional)
$scrolling_height = '200px'; 
$dgrid->SetScrollingSettings($scrolling_height);
If you want to allow multirow operations for DataGrid, set $multirow_option = true;
## *** allow multirow operations
$multirow_option = true;
$multirow_view_type = 'icons'; /* optional - 'icons' or 'dropdownlist' */
$dgrid->AllowMultirowOperations($multirow_option, $multirow_view_type);
You can work with embedded multi-row operations: delete/details or define your own operation, like in example below. Number of operations, that you may define - is not limited.
$multirow_operations = array(
  'delete'  => array('view'=>true),
  'details' => array('view'=>true),
  'my_operation_name' => 
     array('view'=>true, 
           'flag_name'=>'my_flag_name', 
           'flag_value'=>'my_flag_value', 
           'tooltip'=>'Do something with selected', 
           'image'=>'image.gif')
);
$dgrid->SetMultirowOperations($multirow_operations);  
Set CSS parameters for the datagrid. If you want to use your own css class - create folder with needed images in images/YOUR_NEW_CSS/ and YOUR_NEW_CSS.css file in CSS/ folder.
Embedded CSS styles: 'default', 'blue', 'gray', 'green', 'pink', 'empty' and 'x-blue', 'x-gray', 'x-green' (v6.x.x or above)
## *** set CSS class for datagrid
## *** 'default|blue|gray|green|pink|empty|x-blue|x-gray|x-green' or your own css style
$css_class = 'default'; 
$dgrid->SetCssClass($css_class);
Set variables that you use to get access to your page or have passed from the previous page/s.
## *** set variables that used to get access to the page
## *** (like: my_page.php?act=34&id=56 etc.)  
$http_get_vars = array('act', 'id');
$dgrid->SetHttpGetVars($http_get_vars);
If you want to use some ApPHP DataGrid on your page, you need to define other datagrids unique prefixes to allow each datagrid to detect others. You need to define in which mode (view/edit/details) the current datagrid will recognize others.
## *** set other datagrid/s unique prefixes
## *** (if you use few datagrids on the one page)
## *** format (in wich mode to allow processing of other datagrids)
## *** array('unique_prefix'=>array('view'=>true, 'edit'=>true, 'details'=>true), [,...]);
$otherGrids = array('abcd_'=>array('view'=>true, 'edit'=>true, 'details'=>true));
$dgrid->SetOtherDatagrids($otherGrids);  
Set datagrid title (caption).
## *** set DataGrid Caption
$dg_caption = 'My Favorite Lovely ApPHP DataGrid';
$dgrid->SetCaption($dg_caption);



Step 3. Printing & Exporting Settings.


If you want to allow users to view printer-friendly pages and print them - set printing as true.
## *** set printing option: true(default) or false 
$printing_option = true;
$dgrid->AllowPrinting($printing_option); 
If you want to allow users to export datagrid data - set exporting as true and define exporting directory.
## *** initialize the session with session_start();
## *** default exporting directory (requires write permissions): 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', 'doc'=>'true'
);
$dgrid->AllowExportingTypes($exporting_types);



Step 4. Sorting & Paging Settings.


Set sorting option as true, if you want to allow sorting on columns.
## *** set sorting option: true(default) or false 
$sorting_option = true;
$dgrid->AllowSorting($sorting_option);
Set paging option as true, if you want to allow paging on datagrid. If you want to add a column with rows numeration - set $rows_numeration as true. If you want to allow paging by selecting page from dropdown box - set $dropdown_paging as true.
## *** set paging option: true(default) or false 
$paging_option = true;
$rows_numeration = false;
$numeration_sign = 'N #';
$dropdown_paging = false;
$dgrid->AllowPaging($paging_option, $rows_numeration, $numeration_sign, $dropdown_paging);
Set additional paging settings.
$top_paging or $bottom_paging - both define paging (top and bottom) behaviour. We have three parts of the paging line (left, center, right): results, pages and page size dropdownbox. You need to set parameters for each of them. If you don't want to show any of them or all of them - leave it empty Ex.: $bottom_paging = array() or $bottom_paging = array('results'=>true, 'results_align'=>'left');.
If you want to define your own dropdown box with page sizes - you can make it in $pages_array array - see example below or leave it empty. Also you can define default page size in $default_page_size variable.
## *** set paging settings 
$bottom_paging = array(
    'results'=>true, 'results_align'=>'left', 
    'pages'=>true, 'pages_align'=>'center', 
    'page_size'=>true, 'page_size_align'=>'right');
$top_paging = array(
    'results'=>true, 'results_align'=>'left',
    'pages'=>true, 'pages_align'=>'center',
    'page_size'=>true, 'page_size_align'=>'right');
$pages_array = array(
    '10'=>'10', '25'=>'25', '50'=>'50', '100'=>'100', '250'=>'250'
);
$default_page_size = 10;
$paging_arrows = array(
    'first'=>'|<<', 'previous'=>'<<', 'next'=>'>>', 'last'=>'>>|'
);
$dgrid->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size);



Step 5. Filter (search) Settings.


If you want to allow a filtering mode, set $filtering_option as true.
## *** set filtering option: true or false(default)
## *** tips: use ',' (comma) if you want to make search by some words, for ex.: hello, bye, hi
$filtering_option = true;
$dgrid->AllowFiltering($filtering_option);
Set additional filtering settings.
'Caption_1/2/3/.../n'=> - caption for the filtering field
'table'=>'tableName_1/2/3/.../n'
'field'=>'fieldName_1/2/3/.../n' - table and field we want to filter
'filter_condition'=>'' - additional conditions on filtering field (Ex.: 'AND LENGTH(last_name) > 3')
'source'=>'self'|$fill_from_array - take values for filtering field (dropdown list) from the specific array or not
Example:
$fill_from_array = array('0'=>'No', '1'=>'Yes');
Common:
'operator'=>false|true - draw comparison operators dropdown list or not
'order'=>'ASC|DESC' - dropdown list values order (optional)
'type'=>'textbox|dropdownlist|calendar' - view type of filtering filed (textbox - default)
'default_operator' - may be =|!=|<|<=|>|>=|like|%like|like%|%like%|not like
'autocomplete'=>'false|true' - AJAX autocomplete function (for textbox only)
'handler'=>'modules/autosuggest/test.php' - script that processes autocomplete (for autocomplete only). Write path relatively to DATAGRID_DIR constant.
'maxresults'=>'12' - number of results, that autocomplete function returns (for autocomplete only)
'shownoresults'=>'false|true' - show or not 'No Results' box (for autocomplete only)
'case_sensitive'=>false|true - whether filtering is case sensitive
'comparison_type'=>'string|numeric|binary' - filtering comparison type
'on_js_event'=>'' - add here client side javascript function or code
'width'=>'' - defines a width of filtering field
'condition'=>'' - some condition. Ex.: TableName_1.FieldName > 'a' AND TableName_1.FieldName < 'c'
'multiple'=>'false|true' - allow multiple selection for dropdownlist or not
'multiple_size'=>'' - parameter, that defines number of rows shown in dropdownlist
'field_type'=>'' - (optional) if you want to perform rage search, you need to define them separately. For example: 'field_type'=>'from' and 'field_type'=>'to' each field

For the 'enum' type:
'field_view'=>'' - field, that will be shown in dropdownlist: 'field_view'=>'field2' or 'field_view'=>'CONCAT(field1, ",", field2) as field3' or 'field_view'=>'"link" as field3'
'view_type'=>'dropdownlist(default)|radiobutton' - view type of the field
'show_count'=>'' - true or false, shows amount of filtering items, like: members (8)

For the 'calendar' type:
'date_format'=>'' - ('date' or 'datedmy', 'datetime' or 'time') defines date format for calendar field
'calendar_type'=>'' - ('popup' or 'floating') defines calendar view type
## *** set additional filtering settings
$filtering_fields = array(
   'Caption_1'=>array('type'=>'textbox',  'table'=>'tableName_1', 'field'=>'fieldName_1|,fieldName_2', 'filter_condition'=>'', 'show_operator'=>'false', 'default_operator'=>'=', 'case_sensitive'=>'false', 'comparison_type'=>'string|numeric|binary', 'width'=>'', 'on_js_event'=>'', 'default'=>''),
   'Caption_2'=>array('type'=>'textbox',  'table'=>'tableName_2', 'field'=>'fieldName_1|,fieldName_2', 'filter_condition'=>'', 'show_operator'=>'false', 'default_operator'=>'=', 'case_sensitive'=>'false', 'comparison_type'=>'string|numeric|binary', 'width'=>'', 'on_js_event'=>'', 'default'=>'', 'autocomplete'=>'false', 'handler'=>'modules/autosuggest/test.php', 'maxresults'=>'12', 'shownoresults'=>'false'),
   'Caption_3'=>array('type'=>'enum',     'table'=>'tableName_3', 'field'=>'fieldName_1',              'filter_condition'=>'', 'show_operator'=>'false', 'default_operator'=>'=', 'case_sensitive'=>'false', 'comparison_type'=>'string|numeric|binary', 'width'=>'', 'on_js_event'=>'', 'default'=>'', 'source'=>'self'|$fill_from_array, 'view_type'=>'dropdownlist(default)|radiobutton', 'field_view'=>'fieldName_2', 'order_by_field'=>'', 'order_type'=>'ASC|DESC', 'condition'=>'', 'show_count'=>false, 'multiple'=>'false', 'multiple_size'=>'4'),
   'Caption_4'=>array('type'=>'calendar', 'table'=>'tableName_4', 'field'=>'fieldName_1',              'filter_condition'=>'', 'show_operator'=>'false', 'default_operator'=>'=', 'case_sensitive'=>'false', 'comparison_type'=>'string|numeric|binary', 'width'=>'', 'on_js_event'=>'', 'default'=>'', 'calendar_type'=>'popup|floating', 'date_format'=>'date', 'field_type'=>''),
);
$dgrid->SetFieldsFiltering($filtering_fields);

If you want to allow using of default filtering, set AllowDefaultFiltering(true) method. Using of this method means, that datagrid will be opened on default view with this filtering settings.
## *** allow default filtering: default - false
$default_filtering_option = true;
$dgrid->AllowDefaultFiltering($default_filtering_option);



Step 6. View Mode Settings.


Set some properties for view mode table
## *** set table properties
$vm_table_properties = array('width'=>'90%');
$dgrid->SetViewModeTableProperties($vm_table_properties); 
This method sets up columns, that will be viewable.
For all types:
'header'=>'...' - name of the column's header
'type'=>'...' - type of the column. Possible values: label, image, linktoview, linktoedit, link (http://, mailto:, ftp://), password or barchart
'align'=>'...' - horizontal alignment of the column's content (left, center or right)
'sort_type'=>'string|numeric' - type of column sorting
'width'=>'...' - width of the column in pixels or in percents
'wrap'=>'...' - wrapping of the column data (wrap or nowrap)
'text_length'=>'...' - viewable length of the text in characters (any integer number - truncate after this number of characters, '-1' - don't truncate (view a full text))
'tooltip'=>'...' - allows showing tool-tips on mouseover event (if field's text was truncated by 'text_length' attribute)
'tooltip_type'=>'...' - defines a type of tool-tips ('floating' or 'simple')
'case'=>'...' - text case (normal, upper, lower or camel)
'summarize'=>... - summarize values in this column (true or false)
'on_js_event'=>'...' - javascript code or js function on some event. Example: onClick(alert('Clicked!'))

For the 'link' type:
'field_key'=>'field_name_0'|'field_key_1'=>'field_name_1'|..., - field for href parameter in <a href='...field_key_x...'>
'field_data'=>'...', - field for <a href=''>field_data
'href'=>'...' - href parameter, {0}/{1}/... will be changed on 'field_key_0/1/...' value
'target'=>'...' - target parameter

For the 'image' type:
'target_path'=>'...' - relative path to image
'default'=>'...' - default image name
'image_width'=>'...' - viewing width of image
'image_height'=>'...' - viewing height of image
'linkto'=>'...' - ('' or details) link on details mode
'magnify'=>'' - (true or false) allow magnifying of images
'magnify_type'=>'' - ('popup', 'lightbox', 'magnifier') defines a type of magnifying
'magnify_power'=>'2' - number, that defines a power of magnifying

For the 'money' type:
'sign'=>'$' - money sign
'decimal_places'=>'2' - number of decimal places
'dec_separator'=>'.' - sign for separation of decimal digits
'thousands_separator'=>'.' - sign for separation of thousands digits

For the 'barchart' type:
'display_type'=>'...' - ('vertical' or 'horizontal') defines a viewing type
'field'=>'...' - filed name
'maximum_value'=>'...' maximal value for the chart. Number format in SELECT SQL must be equal with number format in max_value.
'value_sign'=>'' - sign that will be displayed near the barchart 'minimum_color'=>'', 'minimum_value'=>'' - minimum color and value 'middle_color'=>'', 'middle_value'=>'' - middle color and value 'maximum_color'=>'', 'maximum_value'=>'100' - maximum color and value

For the 'enum' type:
'source'=>'...' - source for enum type. Possible values: user's pre-defined array

For the 'password' type:
'hide'=>'' - show password (true) or display ****** (false)

For the 'percent' type:
'decimal_places'=>'2' - number of decimal places
'dec_separator'=>'.' - sign for separation of decimal digits

For the 'checkbox' type:
'true_value'=>'...' - set value for checked checkbox
'false_value'=>'...' - set value for unchecked checkbox

For the 'color' type:
'view_type'=>'...' - set value for type of viewing: text or image

## *** set columns in view mode

$vm_columns = array(
  'FieldName_1'=>array('header'=>'Name_A', 'type'=>'label',      'align'=>'left', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'floating|simple', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
  'FieldName_2'=>array('header'=>'Name_B', 'type'=>'image',      'align'=>'left', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'', 'target_path'=>'uploads/', 'default'=>'', 'image_width'=>'50px', 'image_height'=>'30px', 'linkto'=>'', 'magnify'=>'false', 'magnify_type'=>'popup|magnifier|lightbox', 'magnify_power'=>'2'),
  'FieldName_3'=>array('header'=>'Name_C', 'type'=>'linktoview', 'align'=>'left', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'floating|simple', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
  'FieldName_4'=>array('header'=>'Name_D', 'type'=>'linktoedit', 'align'=>'left', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'floating|simple', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
  'FieldName_5'=>array('header'=>'Name_E', 'type'=>'linktodelete', 'align'=>'left', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'floating|simple', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
  'FieldName_6'=>array('header'=>'Name_F', 'type'=>'link',       'align'=>'left', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'floating|simple', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'', 'field_key'=>'field_name_0', 'field_key_1'=>'field_name_1', 'field_data'=>'field_name_2', 'rel'=>'', 'title'=>'', 'target'=>'_self', 'href'=>'{0}'),
  'FieldName_7'=>array('header'=>'Name_G', 'type'=>'link',       'align'=>'left', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'floating|simple', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'', 'field_key'=>'field_name_0', 'field_key_1'=>'field_name_1', 'field_data'=>'field_name_2', 'rel'=>'', 'title'=>'', 'target'=>'_self', 'href'=>'mailto:{0}'),
  'FieldName_8'=>array('header'=>'Name_H', 'type'=>'link',       'align'=>'left', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'floating|simple', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'', 'field_key'=>'field_name_0', 'field_key_1'=>'field_name_1', 'field_data'=>'field_name_2', 'rel'=>'', 'title'=>'', 'target'=>'_self', 'href'=>'http://mydomain.com?act={0}&act={1}&code=ABC'),
  'FieldName_9'=>array('header'=>'Name_I', 'type'=>'linkbutton', 'align'=>'left', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'floating|simple', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'', 'field_key'=>'field_name_0', 'field_key_1'=>'field_name_1', 'field_data'=>'field_name_2', 'href'=>'{0}'),
  'FieldName_10'=>array('header'=>'Name_G', 'type'=>'money',     'align'=>'right','width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'floating|simple', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'', 'sign'=>'$', 'sign_place'=>'before|after', 'decimal_places'=>'2', 'dec_separator'=>'.', 'thousands_separator'=>','),
  'FieldName_11'=>array('header'=>'Name_K', 'type'=>'password',  'align'=>'left', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'floating|simple', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'', 'hide'=>'false'),
  'FieldName_12'=>array('header'=>'Name_L', 'type'=>'percent',   'align'=>'right','width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'floating|simple', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'', 'decimal_places'=>'2', 'dec_separator'=>'.'),
  'FieldName_13'=>array('header'=>'Name_M', 'type'=>'barchart',  'align'=>'left', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'', 'field'=>'', 'value_sign'=>'', 'minimum_color'=>'', 'minimum_value'=>'', 'middle_color'=>'', 'middle_value'=>'', 'maximum_color'=>'', 'maximum_value'=>'100', 'display_type'=>'vertical|horizontal'),
  'FieldName_14'=>array('header'=>'Name_N', 'type'=>'enum',      'align'=>'left', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'floating|simple', 'case'=>'normal|upper|lower|camel', 'summarize'=>'false', 'summarize_sign'=>'', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'', 'source'=>$fill_from_array, 'multiple'=>'false'),
  'FieldName_15'=>array('header'=>'Name_O', 'type'=>'color',     'align'=>'center', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'text_length'=>'-1', 'tooltip'=>'false', 'tooltip_type'=>'floating|simple', 'case'=>'normal|upper|lower|camel', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'', 'view_type'=>'text|image'),
  'FieldName_16'=>array('header'=>'Name_P', 'type'=>'checkbox',  'align'=>'center', 'width'=>'X%|Xpx', 'wrap'=>'wrap|nowrap', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>'', 'true_value'=>1, 'false_value'=>0),
  'FieldName_17'=>array('header'=>'Name_Q', 'type'=>'object',    'align'=>'center', 'width'=>'X%|Xpx', 'height'=>'X%|Xpx', 'sort_type'=>'string|numeric', 'sort_by'=>'', 'visible'=>'true', 'on_js_event'=>''),
  'FieldName_18'=>array('header'=>'Name_R', 'type'=>'blob'),
);
$dgrid->SetColumnsInViewMode($vm_columns);

If you want to get auto-generated columns - set $auto_column_in_view_mode as true.
## *** set auto-generated columns in view mode
$auto_column_in_view_mode = false;
$dgrid->SetAutoColumnsInViewMode($auto_column_in_view_mode);



Step 7. Add/Edit/Details Mode Settings.


Set properties for edit mode table.
## *** set add/edit mode table properties
$em_table_properties = array('width'=>'70%');
$dgrid->SetEditModeTableProperties($em_table_properties);
Set properties for details mode table.
## *** set details mode table properties
$dm_table_properties = array('width'=>'70%');
$dgrid->SetDetailsModeTableProperties($dm_table_properties);
Set settings for add/edit/details modes.
## ***  set settings for add/edit/details modes
// Table for adding and editing
$table_name  = 'table_name';
// Primary key for this table
$primary_key = 'primary_key'; 
// Condition. Ex.: table_name.field = 'xxx'
$condition = '';
$dgrid->SetTableEdit($table_name, $primary_key, $condition);
This method sets up columns, that will be viewable.
For all types:
'header'=>'...' - name of the column's header
'type'=>'...' - type of the column.
Possible values: 
textbox,          textarea, 
label,            password,  
print,            datemdy(mm-dd-yyyy),
enum,             date(yyyy-mm-dd), 
image,            datedmy(dd-mm-yyyy), 
checkbox,         datetime(yyyy-mm-dd hh:mm:ss), 
file,             datetimedmy(dd-mm-yyyy hh:mm:ss),
time(hh:mm:ss),   datetimemdy(mm-dd-yyyy hh:mm:ss),
delimiter,        link (http://, mailto:, ftp://),
hidden
'req_type'=>'...' - field parameters:
first letter: 
    r - required,      s - simple (not required)
second letter: 
    t - text(including datetime), 
    n - numeric,       a - alphabetic,    e - email,
    f - float,         l - login name,    p - password, 
    y - any(generally used for foreign languages),           
    z - zipcode,       i - integer,       v - verified, 
    u - URL,           s - SSN number,    m - telephone,
    b - alphanumeric   c - checked (checkboxes),  r - checked (radiobuttons) 
    x - template,      
    (for example - 'req_type'='rx', 'template'=>'(ddd)-ddd-dd-dd'    
    where d - digit, c - character)
third letter (optional): 
    for numbers: s - signed, u - unsigned, p - positive, n - negative
    for strings: u - upper,  l - lower,    n - normal,   y - any 
'align'=>'...' - field horizontal align
Possible values: left, center, right
'width'=>'...' - width of the field in pixels
'title'=>'...' - title (tooltip) of the field
'readonly'=>'...' - if the filed is readonly (false|true)
'maxlength'=>'...' - maximal size in characters of the field value
'default'=>... - default value for the field (for add mode only)
'unique'=>... - make or not (true|false) validation for unique values for this field
'unique_condition'=>... - validation for unique values for this field by the condition (ex.: field_1 > 1 OR field_2 = 99)
'on_js_event'=>'...' - javascript code or js function on some event. Example: onClick(alert('Clicked!'))

For the 'link' type:
'field_key'=>'field_name_0'|'field_key_1'=>'field_name_1'|..., - field for href parameter in <a href='...field_key_x...'>
'field_data'=>'...', - field for <a href=''>field_data
'href'=>'...' - href parameter, {0}/{1}/... will be changed on 'field_key_0/1/...' value
'target'=>'...' - target parameter

For the 'date|datetime|time' types:
'calendar_type'=>'popup|floating|dropdownlist' - type of calendar
'show_seconds'=>'true' - show seconds or not

For the 'image' type:
Make sure, that target_path directory has 755 permissions
'target_path'=>'...' - relative (or full) path to image
'file_name'=>'...' - set new name for image or use an original file name
'max_file_size'=>'...' - maximal image size allowed. Ex.: 1000, 10K, 1.2M or 1G
'image_width'=>'...' - viewing width of image
'image_height'=>'...' - viewing height of image
'resize_image'=>'' - (true or false) allows resizing of images
'resize_dir'=>'' - specifies a direction of resizing ('down', 'up' or 'both')
'resize_width'=>'' - (Xpx) set new width of resized images (leave blank if you want to save aspect ratio by height)
'resize_height'=>'' - (Xpx) set new height of resized images (leave blank if you want to save aspect ratio by width)
'magnify'=>'' - (true or false) allow magnifying of images
'magnify_type'=>'' - ('popup', 'magnifier' or 'lightbox') defines a type of magnifying
'magnify_power'=>'2' - number, that defines a power of magnifying
'allow_downloading'=>'' - (true or false) allows downloading image in Details Mode
'allowed_extensions'=>'' - comma separated list of allowed extensions for uploaded files
'allow_image_updating'=>'false' - specifies whether to allow image updating without deleting

For the 'file' type:
Make sure, that target_path directory has 755 permissions
'target_path'=>'...' - relative (or full) path to file
'file_name'=>'...' - set new name for file use an original file name
'max_file_size'=>'...' - maximal image size allowed. Ex.: 1000, 10K, 1.2M or 1G
'allow_downloading'=>'' - (true or false) allows downloading file in Details Mode

For the 'checkbox' type:
'true_value'=>'...' - set value for checked checkbox
'false_value'=>'...' - set value for unchecked checkbox

For the 'enum' type:
'source'=>'...' - source for enum type. Possible values: 'self' or from customized array
'view_type'=>'...' - view type of the field: dropdownlist (default), radiobutton or checkbox
'elements_alignment'=>'horizontal|vertical' - type of radiobuttons alignment
'multiple'=>... - true or false (default) - if allow multirows listbox
'multiple_size'=>... - number of rows in multirows listbox (4 - default)

// Fill enum type from the array (optional)
$fill_from_array = array('0'=>'No', '1'=>'Yes', '2'=>'Don't know', '3'=>'My be'); 
For the 'hidden' type:
'default'=>'...' - default value for the field (in Add Mode). You may use NOW or CURRENT_TIMESTAMP.
'value'=>'...' - new value for the field (in Edit Mode)

For the 'textarea' type:
'edit_type'=>'...' - simple view - 'simple' or advanced wysiwyg editor - 'wysiwyg'
'resizable'=>'...' - if the textarea can be resized by mouse: 'both', 'horizontal', 'vertical' or 'none'
'rows'=>'...' - number of rows (default 7)
'cols'=>'...' - number of columns (default - 50)
'upload_images'=>'false' - allow uploading images via textarea or not

For the 'delimiter_1|2|3...' type:
'inner_html'=>'...' - html for delimiter row

For the 'validator' type:
'for_field'=>'...' - name of the field for validation process
'validation_type'=>'password|email' - type of validation field

For the 'password' type:
'hide'=>'' - (true or false) show password or display ******
'generate'=>'' - (true or false) draw button (link) for random generating of password
'cryptography'=>'' - (true or false) is any cryptographic method used
'cryptography_type'=>'' - (aes or md5) define cryptographic method
'aes_cryptography'=>'' - password (key) for aes cryptographic function

For the 'percent' type:
'decimal_places'=>'2' - number of decimal places
'dec_separator'=>'.' - sign for separation of decimal digits

For the 'color' type:
'view_type'=>'dropdownlist' - viewing type: dropdownlist
'save_format'=>'hexcodes' - type of stored data: hexcodes

$em_columns = array(
  'FieldName_1'  =>array('header'=>'Name_A', 'type'=>'textbox',    'req_type'=>'rt', 'width'=>'210px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>''),
  'FieldName_2'  =>array('header'=>'Name_B', 'type'=>'textarea',   'req_type'=>'rt', 'width'=>'210px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'', 'edit_type'=>'simple|wysiwyg', 'resizable'=>'both|horizontal|vertical|none', 'upload_images'=>'false', 'rows'=>'7', 'cols'=>'50'),
  'FieldName_3'  =>array('header'=>'Name_C', 'type'=>'label',      'title'=>'', 'default'=>'', 'visible'=>'true', 'on_js_event'=>''),
  'FieldName_4'  =>array('header'=>'Name_D', 'type'=>'date',       'req_type'=>'rt', 'width'=>'187px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'', 'calendar_type'=>'popup|floating|dropdownlist'),
  'FieldName_5'  =>array('header'=>'Name_E', 'type'=>'datetime',   'req_type'=>'st', 'width'=>'187px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'', 'calendar_type'=>'popup|floating|dropdownlist', 'show_seconds'=>'true'),
  'FieldName_6'  =>array('header'=>'Name_F', 'type'=>'time',       'req_type'=>'st', 'width'=>'90px',  'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'', 'calendar_type'=>'popup|dropdownlist', 'show_seconds'=>'true'),
  'FieldName_7'  =>array('header'=>'Name_G', 'type'=>'image',      'req_type'=>'st', 'width'=>'210px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'', 'target_path'=>'uploads/', 'allow_image_updating'=>'false', 'max_file_size'=>'100000|100K|10M|1G', 'image_width'=>'120px', 'image_height'=>'90px', 'resize_dir'=>'down|up|both', 'resize_image'=>'false', 'resize_width'=>'', 'resize_height'=>'', 'magnify'=>'false', 'magnify_type'=>'popup|magnifier|lightbox', 'magnify_power'=>'2', 'file_name'=>'', 'host'=>'local|remote', 'allow_downloading'=>'false', 'allowed_extensions'=>''),
  'FieldName_8'  =>array('header'=>'Name_H', 'type'=>'password',   'req_type'=>'rp', 'width'=>'210px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'', 'hide'=>'false', 'generate'=>'true', 'cryptography'=>'false', 'cryptography_type'=>'aes|md5', 'aes_password'=>'aes_password'),
  'FieldName_9'  =>array('header'=>'Name_I', 'type'=>'money',      'req_type'=>'rn', 'width'=>'80px',  'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'', 'sign'=>'$', 'sign_place'=>'before|after', 'decimal_places'=>'2', 'dec_separator'=>'.', 'thousands_separator'=>','),
  'FieldName_10' =>array('header'=>'Name_J', 'type'=>'enum',       'req_type'=>'st', 'width'=>'',      'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'', 'source'=>'self'|$fill_from_array, 'view_type'=>'dropdownlist(default)|radiobutton|checkbox', 'elements_alignment'=>'horizontal|vertical', 'multiple'=>'false', 'multiple_size'=>'4'),
  'FieldName_11' =>array('header'=>'Name_K', 'type'=>'print',      'req_type'=>'st', 'width'=>'210px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', ''unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>''),
  'FieldName_12' =>array('header'=>'Name_L', 'type'=>'checkbox',   'req_type'=>'st', 'width'=>'210px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'', 'true_value'=>1, 'false_value'=>0),
  'FieldName_13' =>array('header'=>'Name_M', 'type'=>'file',       'req_type'=>'st', 'width'=>'210px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'', 'target_path'=>'uploads/', 'max_file_size'=>'100000|100K|10M|1G', 'file_name'=>'', 'host'=>'local|remote', 'allow_downloading'=>'false', 'allowed_extensions'=>''),
  'FieldName_14_a' =>array('header'=>'Name_N (for add/edit mode)', 'type'=>'link',   'req_type'=>'st', 'width'=>'210px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>''),
  'FieldName_14_b' =>array('header'=>'Name_N (for details mode)',  'type'=>'link',   'req_type'=>'st', 'width'=>'210px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'', 'field_key'=>'', 'field_key_1'=>'', 'field_data'=>'', 'rel'=>'', 'title'=>'', 'target'=>'_self', 'href'=>'{0}'),
  'FieldName_15' =>array('header'=>'Name_O', 'type'=>'foreign_key','req_type'=>'ri', 'width'=>'', 'title'=>'', 'readonly'=>'false', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true'),
  'FieldName_16' =>array('header'=>'Name_P', 'type'=>'blob',       'req_type'=>'st', 'readonly'=>'false'),
  'FieldName_17' =>array('header'=>'Name_Q', 'type'=>'hidden',     'req_type'=>'st', 'default'=>'', 'value'=>'', 'unique'=>'false', 'visible'=>'true'),
  'FieldName_18' =>array('header'=>'Name_R', 'type'=>'percent',    'req_type'=>'rt', 'width'=>'80px',  'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'', 'decimal_places'=>'2', 'dec_separator'=>'.'),
  'FieldName_19' =>array('header'=>'Name_S', 'type'=>'color',      'req_type'=>'rt', 'width'=>'210px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'unique'=>'false', 'unique_condition'=>'', 'visible'=>'true', 'on_js_event'=>'', 'view_type'=>'dropdownlist|picker', 'save_format'=>'hexcodes'),
  'validator'    =>array('header'=>'Name_T', 'type'=>'validator',  'req_type'=>'rv', 'width'=>'210px', 'title'=>'', 'readonly'=>'false', 'maxlength'=>'-1', 'default'=>'', 'visible'=>'true', 'on_js_event'=>'', 'for_field'=>'', 'validation_type'=>'password|email'),
  'delimiter_1|2|3...'    =>array('inner_html'=>'<br />'
);
$dgrid->SetColumnsInEditMode($em_columns);

If you want to get auto-generated columns - set $auto_column_in_edit_mode as true.
## *** set auto-generated columns in edit mode
$auto_column_in_edit_mode = false;
$dgrid->SetAutoColumnsInEditMode($auto_column_in_edit_mode);



Step 8. Foreign Keys Settings.


Settings for the foreign keys.
'ForeignKey_1/2/3.../n'=>'...' - foreign key from 'Edit' table
'table'=>'...' - foreign table name
'field_key'=>'...' - key in foreign table
'field_name'=>'...' - filed, that will be viewed or virtual field: 'field_name'=>'CONCAT(field1, ",", field2) as field3'
'view_type'=>'...' - view type. Possible values: dropdownlist(default), radiobutton, texbox or label
'condition'=>'...' - some condition. Ex.: Table.FieldName > 'a' AND Table.FieldName < 'c'
'order_by_field'=>'...' - sorting order by the filed
'order_type'=>'...' - sorting type
'on_js_event'=>'...' - javascript code or js function on some event. Example: onClick(alert('Clicked!'))
'show_count'=>'' - true or false, specifies whether to show number of foreign keys in dropdown list

## *** set foreign keys for add/edit/details modes (if there are linked tables)
## *** Ex.: 'condition'=>'Table_1.FieldName > "a" AND Table_1.FieldName < "c"'
## *** Ex.: 'on_js_event'=>'onclick="alert(\'Yes!!!\');"'
$foreign_keys = array(
   'ForeignKey_1'=>array('table'=>'TableName_1', 'field_key'=>'FieldKey_1', 'field_name'=>'FieldName_1', 'view_type'=>'dropdownlist(default)|radiobutton|textbox|label', 'elements_alignment'=>'horizontal|vertical', 'condition'=>'', 'order_by_field'=>'', 'order_type'=>'ASC|DESC', 'show_count'=>'', 'on_js_event'=>''),
   'ForeignKey_2'=>array('table'=>'TableName_2', 'field_key'=>'FieldKey_2', 'field_name'=>'FieldName_2', 'view_type'=>'dropdownlist(default)|radiobutton|textbox|label', 'elements_alignment'=>'horizontal|vertical', 'condition'=>'', 'order_by_field'=>'', 'order_type'=>'ASC|DESC', 'show_count'=>'', 'on_js_event'=>'')
);
$dgrid->SetForeignKeysEdit($foreign_keys);



Step 9. Bind the DataGrid.


Now we need to bind our DataDrid and draw it on the screen. If you don't need to draw DataGrid on the screen for some reason - call this method with 'false' parameter $dgrid->Bind(true);. Also, to separate binding and displaying use $dgrid->Bind(false) and then $dgrid->Show().
*** bind the DataGrid and draw it on the screen
$dgrid->Bind(true);
ob_end_flush();



Non-Documented features and functions.

Properties


Allows automatical getting focus on the first displayed field in edit mode (default - false)
firstFieldFocusAllowed = true|false;
Hides DataGrid before searching and shows DataGrid after the search is completed (default - false)
hideGridBeforeSearch = true|false;
Return Datagrid to specified mode after updating (default - view)
modeAfterUpdate = 'edit|details';
Define a text, which displayed when a dataset is empty
noDataFoundText = 'No data found';
Block all operations (Add/Update/Delete/Upload) on DataGrid
isDemo = true|false;
Allows displaying additional links etc. at the top of DataGrid
navigationBar = '';
In view mode: defines aggregate function - SUM_TIME, SUM, AVG, MAX or MIN
summarizeFunction = 'SUM';
In view mode: defines displaying alignment of controls ('' or 'grouped')
controlsDisplayingType = 'grouped';
Defines using of escaping special characters in a string
allowRealEscape = true|false;
Defines week first day floating calendar (0 - sunday, default)
weekStartingDay = 1|2...7;
Defines initial state of filtering block - 'closed' or 'opened'
initFilteringState = '';
Defines a separator for datetime fields (private property, allowed values: -,/,- or :)
dtSeparator = '-';
Defines a maximum number of allowed records to be inserted(public)
maximumAllowedRecords = '100';
Defines whether to upload files before form submission ('by_one') or with submission ('all')
uploadType = 'by_one'; // all|by_one (default);
Defines whether to enclose table and field names with backquotes (private property, allowed values: true or false)
addBackQuotes = true;
Defines array of 'accessKeys' for mode buttons.
accessKeys = array('add'=>'a', 'edit'=>'e', 'details'=>'v', 'update'=>'u', 'delete'=>'d');
Defines exporting directory (public property, default: 'tmp/export/')
exportingDirectory = 'tmp/export/';
Defines whether to add ID attribute for elements in View mode (default - false)
drawElementIdInViewMode = true|false;
Defines whether to allow hide icon in filtering mode (default - true)
filteringHideIconAllowed = true|false;
Defines whether to allow refresh page icon (default - true)
refreshPageIconAllowed = true|false;
Defines whether to force using of lower case for field names (default - false)
forceFieldsLowercase = true|false;
Defines whether to use new type of printing (default - no)
$printType = 'old|new';
Defines whether to show buttons at the top of the page (default - false)
$drawTopButtons = true;


Methods


Executes SQL query - use it after dataSource() method only (after the using dataSource() need to be recalled)
ExecuteSql()

// Example:
// Usage: PEAR: $dSet->fetchRow() and $dSet->numCols()
//        PDO: $dSet->fetch() and $dSet->columnCount() 
// $sql = 'SELECT * FROM Presidents WHERE CountryID = '.(int)$_GET['f_rid'];
// $dSet = $dgrid->ExecuteSql($sql);
// while($row = $dSet->fetchRow()){
//  for($c = 0; ($c < $dSet->numCols()); $c++){ echo $row[$c].' '; }
//  echo '<br>';
// }
Returns first column data from SELECT SQL - use it after DataSource() method only (using this method before bind() requires redefenition of DataSource())
SelectSqlItem()

// Example:
// $sql = 'SELECT COUNT(*) FROM Presidents WHERE CountryID = '.(int)$_GET['f_rid'];
// $presidents = $dgrid->SelectSqlItem($sql);
Allows rows highlighting (default - true)
AllowHighlighting(true|false)
Display validation error all together or separately
SetJsErrorsDisplayStyle('all'|'each')
Returns next id of edit table
GetNextId()
Returns current id of edit table
GetCurrentId()
Defines header text for columns in edit mode
SetHeadersInColumnarLayout('Field Name', 'Field Value')
Re-defines DataGrid messages in add/update or delete modes
SetDgMessages(array(
  'add_success'=>'',
  'add_error'=>'',
  'update_success'=>'',
  'update_error'=>'',
  'delete_success'=>'',
  'delete_error'=>''
));
Returns true value, if current operation was successfully completed
IsOperationCompleted()
Returns true value, if some data wqas found
IsDataFound()
Ignore HTML tag
IgnoreBaseTag()
Display loading image
DisplayLoadingImage()
Set number format for summarize functions
SetSummarizeNumberFormat('2', '.', ',', '€');
Set number of columns for filtering with Tabular layout
SetFilteringTabularLayoutColumns('2');
Set default timezone
SetDefaultTimezone('America/Los_Angeles');
Set cache directory
SetCacheDirectory();
Force data encoding
ForceDatabaseEncoding(true);
Allow using of top anchor
AllowTopAnchor(true);
Allow using of absolute paths
UseAbsolutePath(true);
Option 'autocommit' for IBM db driver (must be placed after before DataSource())
SetAutocommit(true);
Database 'schema' option for IBM db driver (must be placed after before DataSource())
SetDbSchema('schema_name');

Attributes


In view mode - displays a tooltip for header
'header_tooltip'=>''
In view mode - defines a header tooltip type ('simple' or 'floating')
'header_tooltip_type'=>''
In view mode - alignment of text in header in all modes
'header_align'=>'left|center|right'
In view mode
'sortable'=>'false|true'
In view mode - displays field data without HTML formatting
'type'=>'data'
In edit mode: 'Autocomplete' attribute for textboxes in add/edit modes (default - 'on')
'autocomplete'=>'on|off';
In edit mode: 'align' attribute for fields in add/edit modes
'align'=>'left|center|right';
Attributes in view mode for labels and in view/add/edit/details modes for textboxes
'pre_addition'=>'', 'post_addition'=>''
Runs user's pre-defined function on_item_created event attributes in view/add/edit/details modes for customized work with field value. This function must be defined with 1 parameter, that will get fild's data. Ex.: function function_name($field_value){ ... return $new_field_value;}
'on_item_created'=>'function_name'
In view mode - defines aggregate function for certain field - SUM|AVG|MAX|MIN|SUM_TIME
'summarize_function'=>'SUM'
Defines whether to show this field on printing (default - true)
'show_on_print'=>true
Defines whether to show this field on exporting (default - true)
'show_on_export'=>true
Adds to column up/down arrows and allows to change row's order (true or false - default). Requires using of session_start();
'movable'=>true;
Defines table alias for filtering fields to prevent name overlapping
'table_alias'=>''
Defines whether to allow using of NULLs for empty fields as default value
'default_null'=>'true'
Defines a type of file storage - standard (link) or blob (for 'file' types). Additional parameters: 'blob_filetype'=>'', 'blob_filename'=>'', 'blob_filesize'=>'' - specifies additional fields (must be defined in database table).
'save_as'=>'blob'
Defines a placeholder for text fields in Add/Edit modes and Filtering section
'placeholder'=>''
Defines a mode, where condition for foreign keys will work ('add' or 'edit')
'condition_mode'=>''

Features


Allows using user's javascript function for extra checkings on form submission in edit mode.
Attention: make sure you write unique_prefix with correct case: lower, upper or camel. Exactly, like it was defined.
// Example:
<script type='text/javascript'>
     function unique_prefix_onSubmitMyCheck(){
       if(document.getElementById('ryyfirst_name').value =='x'){
          alert('Please check ...  X is invalid!!!');
          return false;
       }  
       return true;
   }	
</script>
Allows reloading form in Edit mode

'on_js_event'=>'onchange="_dgFormAction(\'\', \'\', \''.$dgrid->uniquePrefix.'\', \''.$dgrid->HTTP_URL.'\', \''.$_SERVER['QUERY_STRING'].'\', \'post\', \''.$_REQUEST[$dgrid->uniquePrefix.'mode'].'\')"'

true - draw DataGrid on the screen
false - do all needed actions, but don't draw datagrid on the screen
Bind(true|false)



Tricks.


1. Set default value, that disappears on focus:
'default'=>'http://www.website.com', 'on_js_event'=>'onBlur="if(this.value == \'\') this.value = \'http://www.website.com\'; this.style.color=\'#f68d6f\';" onClick="if(this.value==\'http://www.website.com\') this.value=\'\'; this.style.color=\'#000000\';"'

2. Set unique value for uploading image:
a) 'file_name'=>'img_'.((isset($_REQUEST['prfx_mode']) && ($_REQUEST['prfx_mode'] == 'add')) ? $dgrid->GetNextId() : $dgrid->GetCurrentId())
b) 'file_name'=>'img_'.((isset($_REQUEST['prfx_mode']) && ($_REQUEST['prfx_mode'] == 'add')) ? $dgrid->GetRandomString('10') : $dgrid->GetCurrentId())

3. Passing parameters to Javascript function on 'on_js_event'=>'' for 'link' and 'label' fields:
'field_key'=>'', 'field_key_1'=>'', 'on_js_event'=>'my_finction({0},{1})' 



Create Your Free Account
Please remember that this information is essential to use our services correctly.
After creating the account you will be able to download all of our FREE products.
Fields marked with * are mandatory






Please send me information about updates, new products, specials and discounts from ApPHP!
We recommend that your password should be at least 6 characters long and should be different from your username/email. Please use only letters of the English alphabet to enter your name.

Your e-mail address must be valid. We use e-mail for communication purposes (order notifications, etc). Therefore, it is essential to provide a valid e-mail address to be able to use our services correctly.

All your private data is confidential. We will never sell, exchange or market it in any way. Please refer to Privacy Policy.

By clicking "Create Account", you are indicating that you have read and agree to the ApPHP Terms & Conditions.