Sample 2-4. Advanced PHP DG code.

    1. All modes (Add/Edit/Details/Delete/View).
    2. All features.
    3. Two DataGrids on one page.
    4. Customized layout in details mode.

   View LIVE DEMO on this sample   BACK to Examples Page

Show Plain Text »
  1. <?php
  2.    
  3. ## +---------------------------------------------------------------------------+
  4. ## | 1. Creating & Calling:                                                    |
  5. ## +---------------------------------------------------------------------------+
  6. ##  *** define a relative (virtual) path to datagrid.class.php file and "pear"
  7. ##  *** directory (relatively to the current file)
  8. ##  *** RELATIVE PATH ONLY ***
  9.   define ("DATAGRID_DIR", "datagrid/");                     /* Ex.: "datagrid/" */
  10.   require_once(DATAGRID_DIR."datagrid.class.php");
  11.  
  12. ##  *** creating variables that we need for database connection
  13.   $DB_USER="username";            
  14.   $DB_PASS="password";          
  15.   $DB_HOST="localhost";      
  16.   $DB_NAME="database_name";    
  17.  
  18.   ob_start();
  19. ##  *** put a primary key on the first place
  20.   $sql=" SELECT "
  21.    ."demo_countries.id, "
  22.    ."demo_countries.region_id, "
  23.    ."demo_regions.name as region_name, "
  24.    ."demo_countries.name as country_name, "
  25.    ."demo_countries.description, "
  26.    ."demo_countries.picture_url, "
  27.    ."demo_countries.picture_url_1, "
  28.    ."demo_countries.independent_date, "
  29.    ."demo_countries.independent_time, "
  30.    ."FORMAT(demo_countries.population, 0) as population, "  
  31.    ."(SELECT COUNT(demo_presidents.id) FROM demo_presidents WHERE demo_presidents.country_id = demo_countries.id) as presidents, "
  32.    ." CASE WHEN demo_countries.is_democracy = 1 THEN "Yes" ELSE "No" END as is_democracy "
  33.    ."FROM demo_countries INNER JOIN demo_regions ON demo_countries.region_id=demo_regions.id ";
  34. ##  *** set needed options and create a new class instance
  35.   $debug_mode = false;        /* display SQL statements while processing */    
  36.   $messaging = true;          /* display system messages on a screen */
  37.   $unique_prefix = "f_";    /* prevent overlays - must be started with a letter */
  38.   $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix);
  39. ##  *** set data source with needed options
  40.   $default_order = array("name"=>"ASC");
  41.   $dgrid->DataSource("PDO", "mysql", $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS, $sql, $default_order);            
  42.  
  43. ## +---------------------------------------------------------------------------+
  44. ## | 2. General Settings:                                                      |
  45. ## +---------------------------------------------------------------------------+
  46.  $postback_method = "post";
  47.  $dgrid->SetPostBackMethod($postback_method);
  48. ##  *** set encoding and collation (default: utf8/utf8_unicode_ci)
  49.  $dg_encoding = "utf8";
  50.  $dg_collation = "utf8_unicode_ci";
  51.  $dgrid->SetEncoding($dg_encoding, $dg_collation);
  52. ##  *** set interface language (default - English)
  53.  $dg_language = "en";  
  54.  $dgrid->SetInterfaceLang($dg_language);
  55. ##  *** set direction: "ltr" or "rtr" (default - "ltr")
  56.  $direction = "ltr";
  57.  $dgrid->SetDirection($direction);
  58. ##  *** set layouts: 0 - tabular(horizontal) - default, 1 - columnar(vertical)
  59.  $layouts = array("view"=>"0", "edit"=>"1", "details"=>"2", "filter"=>"1");
  60.  $dgrid->SetLayouts($layouts);
  61.  
  62.  $details_template = array("header"=>"", "body"=>"", "footer"=>"");
  63.  $details_template["body"] = "
  64.    <table dir="ltr" class="x-blue_dg_table" align="center" width="60%">
  65.    <tr class="class_tr">
  66.        <td width="20%" class="class_td" align="center">{picture_url}</td>
  67.        <td width="20%" class="class_td" align="center">{picture_url_1}</td>
  68.        <td width="60%">
  69.            <table border=0>
  70.                <tr class="class_tr"><td class="x-blue_dg_td class_left" style="border:0px" nowrap><b>Region:</b> </td><td class="x-blue_dg_td class_left"  style="border:0px">{region_id}</td></tr>
  71.                <tr class="class_tr"><td class="x-blue_dg_td class_left" style="border:0px" nowrap><b>Country:</b> </td><td class="x-blue_dg_td class_left"  style="border:0px">{name}</td></tr>
  72.                <tr class="class_tr"><td class="x-blue_dg_td class_left" style="border:0px" nowrap><b>Independence Day:</b> </td><td class="x-blue_dg_td class_left"  style="border:0px">{independent_date}</td></tr>
  73.                <tr class="class_tr"><td class="x-blue_dg_td class_left" style="border:0px" nowrap><b>Democracy?</b> </td><td class="x-blue_dg_td class_left"  style="border:0px">{is_democracy}</td></tr>
  74.                <tr class="class_tr"><td class="x-blue_dg_td class_left" style="border:0px" nowrap><b>Population:</b> </td><td class="x-blue_dg_td class_left"  style="border:0px">{population}</td></tr>
  75.                <tr class="class_tr"><td class="x-blue_dg_td class_left" style="border:0px" nowrap><b>Description:</b> </td><td class="x-blue_dg_td class_left" style="border:0px">{description}</td></tr>
  76.            </table>
  77.        </td>
  78.    </tr>    
  79.    </table>
  80.    <br>
  81.    <table dir="ltr" class="class_table" align="center" width="60%">
  82.    <tr class="class_tr">    
  83.        <th></th>
  84.        <th width="100px" class="x-blue_dg_th class_right" align="right" wrap >[BACK]</th>
  85.    </tr>
  86.    </table>
  87.    <br><br><br>
  88. ";
  89.  $dgrid->SetTemplates("","",$details_template);
  90.  
  91. ##  *** set modes for operations ("type" => "link|button|image")
  92. ##  *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
  93. $modes = array(
  94.    "add"         =>array("view"=>true, "edit"=>false, "type"=>"link"),
  95.    "edit"        =>array("view"=>true, "edit"=>true,  "type"=>"link", "byFieldValue"=>""),
  96.     "cancel"  =>array("view"=>true, "edit"=>true,  "type"=>"link"),
  97.     "details" =>array("view"=>true, "edit"=>false, "type"=>"link"),
  98.     "delete"  =>array("view"=>true, "edit"=>true,  "type"=>"image")
  99.  );
  100.  $dgrid->SetModes($modes);
  101. ##  *** allow scrolling on datagrid
  102. /// $scrolling_option = false;
  103. /// $dgrid->AllowScrollingSettings($scrolling_option);  
  104. ##  *** set scrolling settings (optional)
  105. /// $scrolling_width = "90%";
  106. /// $scrolling_height = "100%";
  107. /// $dgrid->SetScrollingSettings($scrolling_width, $scrolling_height);
  108. ##  *** allow mulirow operations
  109. $multirow_option = true;
  110.  $dgrid->AllowMultirowOperations($multirow_option);
  111.  $multirow_operations = array(
  112.     "delete"  => array("view"=>true),
  113.     "details" => array("view"=>true)
  114.  );
  115.  $dgrid->SetMultirowOperations($multirow_operations);  
  116. ##  *** set CSS class for datagrid
  117. $css_type = "default";
  118.  $dgrid->SetCssClass($css_class);
  119. ##  *** set variables that used to get access to the page (like: my_page.php?act=34&id=56 etc.)
  120. $http_get_vars = array("skin");
  121.  $dgrid->SetHttpGetVars($http_get_vars);
  122. ##  *** set other datagrid/s unique prefixes (if you use few datagrids on one page)
  123. ##  *** format (in wich mode to allow processing of another datagrids)
  124. ##  *** array("unique_prefix"=>array("view"=>true|false, "edit"=>true|false, "details"=>true|false));
  125. $anotherDatagrids = array("fp_"=>array("view"=>false, "edit"=>true, "details"=>false));
  126.  $dgrid->SetAnotherDatagrids($anotherDatagrids);  
  127. ##  *** set DataGrid caption
  128. $dg_caption = "<b>My Favorite Lovely ApPHP DataGrid</b>";
  129.  $dgrid->SetCaption($dg_caption);
  130.  
  131. ## +---------------------------------------------------------------------------+
  132. ## | 3. Printing & Exporting Settings:                                         |
  133. ## +---------------------------------------------------------------------------+
  134. ##  *** set printing option: true(default) or false
  135. $printing_option = true;
  136.  $dgrid->AllowPrinting($printing_option);
  137. ##  *** set exporting option: true(default) or false
  138. $exporting_option = true;
  139.  $dgrid->AllowExporting($exporting_option);
  140.  
  141. ## +---------------------------------------------------------------------------+
  142. ## | 4. Sorting & Paging Settings:                                             |
  143. ## +---------------------------------------------------------------------------+
  144. ##  *** set sorting option: true(default) or false
  145. $sorting_option = true;
  146.  $dgrid->AllowSorting($sorting_option);              
  147. ##  *** set paging option: true(default) or false
  148. $paging_option = true;
  149.  $rows_numeration = false;
  150.  $numeration_sign = "N #";      
  151.  $dgrid->AllowPaging($paging_option, $rows_numeration, $numeration_sign);
  152. ##  *** set paging settings
  153. $bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
  154.  $top_paging = array();
  155.  $pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
  156.  $default_page_size = 10;
  157.  $dgrid->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size);
  158.  
  159. ## +---------------------------------------------------------------------------+
  160. ## | 5. Filter Settings:                                                       |
  161. ## +---------------------------------------------------------------------------+
  162. ##  *** set filtering option: true or false(default)
  163. $filtering_option = true;
  164.  $dgrid->AllowFiltering($filtering_option);
  165. ##  *** set aditional filtering settings
  166.  $fill_from_array = array("10000"=>"10000", "250000"=>"250000", "5000000"=>"5000000", "25000000"=>"25000000", "100000000"=>"100000000");
  167.   $filtering_fields = array(
  168.     "Country"     =>array("table"=>"demo_countries", "field"=>"name", "source"=>"self", "operator"=>true, "default_operator"=>"like", "type"=>"textbox", "case_sensitive"=>true,  "comparison_type"=>"string"),
  169.     "Region"      =>array("table"=>"demo_regions",   "field"=>"name", "source"=>"self", "order"=>"DESC", "operator"=>true, "type"=>"enum", "case_sensitive"=>false,  "comparison_type"=>"binary"),
  170.     "Date"        =>array("table"=>"demo_countries", "field"=>"independent_date", "source"=>"self", "operator"=>true, "type"=>"textbox", "case_sensitive"=>false,  "comparison_type"=>"string"),      
  171.     "Population"  =>array("table"=>"demo_countries", "field"=>"population", "source"=>$fill_from_array, "order"=>"DESC", "operator"=>true, "type"=>"dropdownlist", "case_sensitive"=>false, "comparison_type"=>"numeric")
  172.   );
  173.   $dgrid->SetFieldsFiltering($filtering_fields);
  174.  
  175. ## +---------------------------------------------------------------------------+
  176. ## | 6. View Mode Settings:                                                    |
  177. ## +---------------------------------------------------------------------------+
  178. ##  *** set view mode table properties
  179. /// $vm_table_properties = array("width"=>"90%");
  180. /// $dgrid->SetViewModeTableProperties($vm_table_properties);  
  181. ##  *** set columns in view mode
  182. ##  *** Ex.: "on_js_event"=>"onclick='alert("Yes!!!");'"
  183. ##  ***      "barchart" : number format in SELECT SQL must be equal with number format in max_value
  184. $vm_colimns = array(
  185.     "region_name"  =>array("header"=>"Region Name",      "type"=>"label", "width"=>"130px", "align"=>"left",   "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal"),
  186.     "country_name" =>array("header"=>"Country Name",     "type"=>"linktoedit", "align"=>"left", "width"=>"130px", "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal", "summarize"=>false, "on_js_event"=>""),
  187.     "population"   =>array("header"=>"Population",       "type"=>"label", "summarize"=>true, "align"=>"right",  "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal"),
  188.     "presidents"   =>array("header"=>"Presidents",       "type"=>"label", "summarize"=>true, "align"=>"right",  "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal"),
  189.     "description"  =>array("header"=>"Short Description","type"=>"label", "align"=>"left",   "wrap"=>"wrap",   "text_length"=>"15", "case"=>"lower"),
  190.     "picture_url"  =>array("header"=>"Picture #1",          "type"=>"image", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal", "summarize"=>false, "on_js_event"=>"", "target_path"=>"uploads/", "default"=>"", "image_width"=>"17px", "image_height"=>"17px"),
  191.     "picture_url_1"=>array("header"=>"Picture #2",          "type"=>"image", "align"=>"center", "width"=>"", "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal", "summarize"=>false, "on_js_event"=>"", "target_path"=>"uploads/", "default"=>"", "image_width"=>"17px", "image_height"=>"17px"),
  192.   );
  193.   $dgrid->SetColumnsInViewMode($vm_colimns);
  194.  
  195. ## +---------------------------------------------------------------------------+
  196. ## | 7. Add/Edit/Details Mode Settings:                                        |
  197. ## +---------------------------------------------------------------------------+
  198. ##  *** set add/edit mode table properties
  199. /// $em_table_properties = array("width"=>"70%");
  200. /// $dgrid->SetEditModeTableProperties($em_table_properties);
  201. ##  *** set details mode table properties
  202. /// $dm_table_properties = array("width"=>"70%");
  203. /// $dgrid->SetDetailsModeTableProperties($dm_table_properties);
  204. ##  ***  set settings for add/edit/details modes
  205.  $table_name  = "demo_countries";
  206.  $primary_key = "id";
  207.  $condition   = "";
  208.  $dgrid->SetTableEdit($table_name, $primary_key, $condition);
  209. ##  *** set columns in edit mode
  210.  $fill_from_array = array("10000"=>"10000", "250000"=>"250000", "5000000"=>"5000000", "25000000"=>"25000000", "100000000"=>"100000000");
  211.   $em_columns = array(
  212.     "region_id"        =>array("header"=>"Region",           "type"=>"textbox",  "width"=>"210px", "req_type"=>"rt", "title"=>"Region Name"),
  213.     "name"             =>array("header"=>"Country",          "type"=>"textbox",  "width"=>"210px", "req_type"=>"ry", "title"=>"Country Name", "unique"=>true),
  214.     "description"      =>array("header"=>"Short Descr.",     "type"=>"textarea", "width"=>"210px", "req_type"=>"rt", "title"=>"Short Description", "edit_type"=>"wysiwyg", "rows"=>"7", "cols"=>"50"),
  215.     "population"       =>array("header"=>"Peoples",          "type"=>"enum",     "source"=>$fill_from_array, "view_type"=>"dropdownlist",  "width"=>"139px", "req_type"=>"ri", "title"=>"Population (Peoples)"),
  216.     "picture_url"      =>array("header"=>"Image URL #1",        "type"=>"image",    "req_type"=>"st", "width"=>"210px", "title"=>"Picture", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "on_js_event"=>"", "target_path"=>"uploads/", "max_file_size"=>"100K", "image_width"=>"100px", "image_height"=>"100px", "file_name"=>"", "host"=>"local"),
  217.     "picture_url_1"    =>array("header"=>"Image URL #2",        "type"=>"image",    "req_type"=>"st", "width"=>"210px", "title"=>"Picture", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "on_js_event"=>"", "target_path"=>"uploads/", "max_file_size"=>"100K", "image_width"=>"100px", "image_height"=>"100px", "file_name"=>"", "host"=>"local"),
  218.     "is_democracy"     =>array("header"=>"Is Democracy",     "type"=>"checkbox", "true_value"=>1, "false_value"=>0,  "width"=>"210px", "req_type"=>"sy", "title"=>"Is Democraty"),
  219.     "independent_date" =>array("header"=>"Independence Day", "type"=>"date",     "width"=>"210px", "req_type"=>"rt", "title"=>"Independence Day"),
  220.     "independent_time" =>array("header"=>"Independence Time", "type"=>"time",     "width"=>"210px", "req_type"=>"rt", "title"=>"Independence Time")
  221.   );
  222.   $dgrid->SetColumnsInEditMode($em_columns);
  223.  
  224.  $foreign_keys = array(
  225.     "region_id"=>array("table"=>"demo_regions", "field_key"=>"id", "field_name"=>"name", "view_type"=>"dropdownlist", "order_by_field"=>"name", "order_type"=>"ASC")
  226.  );
  227.  $dgrid->SetForeignKeysEdit($foreign_keys);
  228.  
  229. ## +---------------------------------------------------------------------------+
  230. ## | 8. Bind the DataGrid:                                                     |
  231. ## +---------------------------------------------------------------------------+
  232. ##  *** bind the DataGrid and draw it on the screen
  233.  $dgrid->Bind();        
  234.   ob_end_flush();
  235. ##
  236. ################################################################################  
  237.  
  238. // if we in EDIT mode of the first datagrid
  239. if(isset($_GET["f_mode"]) && ($_GET["f_mode"] == "edit")){
  240.    
  241.    ## +---------------------------------------------------------------------------+
  242.    ## | 1. Creating & Calling:                                                    |
  243.    ## +---------------------------------------------------------------------------+
  244.  
  245.       ob_start();
  246.    ##  *** put a primary key on the first place
  247.      $sql=" SELECT "
  248.        ."demo_presidents.id, "
  249.        ."demo_presidents.country_id, "
  250.        ."demo_presidents.name, "
  251.        ."demo_presidents.birth_date, "
  252.        ."demo_presidents.status "
  253.        ."FROM demo_presidents INNER JOIN demo_countries ON demo_presidents.country_id=demo_countries.id "      
  254.        ."WHERE presidents.country_id = ".$dgrid->GetCurrentId()." ";
  255.    ##  *** set needed options and create a new class instance
  256.       $debug_mode = false;        /* display SQL statements while processing */    
  257.       $messaging = true;          /* display system messages on a screen */
  258.       $unique_prefix = "fp_";    /* prevent overlays - must be started with a letter */
  259.       $dgrid1 = new DataGrid($debug_mode, $messaging, $unique_prefix);
  260.    ##  *** set data source with needed options
  261.       $default_order = array("id"=>"DESC");
  262.       $dgrid1->DataSource("PDO", "mysql", $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS, $sql, $default_order);
  263.  
  264.    ## +---------------------------------------------------------------------------+
  265.    ## | 2. General Settings:                                                      |
  266.    ## +---------------------------------------------------------------------------+
  267.    ##  *** set encoding and collation (default: utf8/utf8_unicode_ci)
  268.      $dg_encoding = "utf8";
  269.      $dg_collation = "utf8_unicode_ci";
  270.      $dgrid1->SetEncoding($dg_encoding, $dg_collation);
  271.    ##  *** set interface language (default - English)
  272.      $dg_language = "en";  
  273.      $dgrid1->SetInterfaceLang($dg_language);
  274.    ##  *** set direction: "ltr" or "rtr" (default - "ltr")
  275.      $direction = "ltr";
  276.      $dgrid1->SetDirection($direction);
  277.    ##  *** set layouts: 0 - tabular(horizontal) - default, 1 - columnar(vertical)
  278.      $layouts = array("view"=>0, "edit"=>0, "filter"=>1);
  279.      $dgrid1->SetLayouts($layouts);
  280.    ##  *** set modes for operations ("type" => "link|button|image")
  281.    ##  *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
  282.      if($_GET["f_mode"] == "edit"){    
  283.         $modes = array(
  284.             "add"=>array("view"=>true, "edit"=>false, "type"=>"link"),
  285.             "edit"=>array("view"=>true, "edit"=>true, "type"=>"link", "byFieldValue"=>""),
  286.             "cancel"=>array("view"=>true, "edit"=>true, "type"=>"link"),
  287.             "details"=>array("view"=>false, "edit"=>false, "type"=>"link"),
  288.             "delete"=>array("view"=>true, "edit"=>false, "type"=>"image")
  289.         );
  290.       }else{
  291.         $modes = array(
  292.             "add"=>array("view"=>false, "edit"=>false, "type"=>"link"),
  293.             "edit"=>array("view"=>false, "edit"=>false, "type"=>"link", "byFieldValue"=>""),
  294.             "cancel"=>array("view"=>false, "edit"=>true, "type"=>"link"),
  295.             "details"=>array("view"=>false, "edit"=>false, "type"=>"link"),
  296.             "delete"=>array("view"=>false, "edit"=>false, "type"=>"image")
  297.         );
  298.       }
  299.       $dgrid1->SetModes($modes);
  300.     ##  *** allow mulirow operations
  301.       $multirow_option = true;
  302.       $dgrid1->AllowMultirowOperations($multirow_option);
  303.       $multirow_operations = array(
  304.        "delete"  => array("view"=>true),
  305.        "details" => array("view"=>true),
  306.      );
  307.      $dgrid1->SetMultirowOperations($multirow_operations);  
  308.     ##  *** set CSS class for datagrid
  309.      $css_type = "embedded";
  310.      $dgrid1->SetCssClass($css_class, $css_type);
  311.     ##  *** set other datagrid/s unique prefixes (if you use few datagrids on one page)
  312.      $anotherDatagrids = array("f_"=>array("view"=>true, "edit"=>true, "details"=>true));
  313.      $dgrid1->SetAnotherDatagrids($anotherDatagrids);  
  314.     ##  *** set DataGrid caption
  315.      $dg_caption = "Presidents";
  316.      $dgrid1->SetCaption($dg_caption);
  317.  
  318.    ## +---------------------------------------------------------------------------+
  319.    ## | 3. Printing & Exporting Settings:                                         |
  320.    ## +---------------------------------------------------------------------------+
  321.    ##  *** set printing option: true(default) or false
  322.      $printing_option = false;
  323.      $dgrid1->AllowPrinting($printing_option);
  324.    ##  *** set exporting option: true(default) or false
  325.      $exporting_option = false;
  326.      $dgrid1->AllowExporting($exporting_option);
  327.  
  328.    ## +---------------------------------------------------------------------------+
  329.    ## | 4. Sorting & Paging Settings:                                             |
  330.    ## +---------------------------------------------------------------------------+
  331.    ##  *** set sorting option: true(default) or false
  332.      $sorting_option = true;
  333.      $dgrid1->AllowSorting($sorting_option);              
  334.    ##  *** set paging option: true(default) or false
  335.      $paging_option = true;
  336.      $rows_numeration = false;
  337.      $numeration_sign = "N #";      
  338.      $dgrid1->AllowPaging($paging_option, $rows_numeration, $numeration_sign);
  339.    ##  *** set paging settings
  340.      $bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
  341.      $top_paging = array();
  342.      $pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
  343.      $default_page_size = 10;
  344.      $dgrid1->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size);
  345.  
  346.    ## +---------------------------------------------------------------------------+
  347.    ## | 5. Filter Settings:                                                       |
  348.    ## +---------------------------------------------------------------------------+
  349.    ##  *** set filtering option: true or false(default)
  350.      $filtering_option = false;
  351.      $dgrid1->AllowFiltering($filtering_option);
  352.  
  353.    ## +---------------------------------------------------------------------------+
  354.    ## | 6. View Mode Settings:                                                    |
  355.    ## +---------------------------------------------------------------------------+
  356.    ##  *** set view mode table properties
  357.      $vm_table_properties = array("width"=>"70%");
  358.      $dgrid1->SetViewModeTableProperties($vm_table_properties);  
  359.    ##  *** set columns in view mode
  360.    ##  ***      "barchart" : number format in SELECT SQL must be equal with number format in max_value
  361.      $vm_colimns = array(
  362.           "name"       =>array("header"=>"Name",        "type"=>"label", "align"=>"left",  "wrap"=>"wrap",   "text_length"=>"20", "case"=>"normal"),
  363.           "birth_date" =>array("header"=>"Birth Date",  "type"=>"label", "align"=>"center",  "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal"),
  364.           "status"     =>array("header"=>"Status",      "type"=>"label", "align"=>"center",  "wrap"=>"nowrap", "text_length"=>"30", "case"=>"normal")
  365.      );
  366.      $dgrid1->SetColumnsInViewMode($vm_colimns);
  367.    ##  *** set auto-genereted columns in view mode
  368.    //  $auto_column_in_view_mode = false;
  369.    //  $dgrid1->SetAutoColumnsInViewMode($auto_column_in_view_mode);
  370.  
  371.    ## +---------------------------------------------------------------------------+
  372.    ## | 7. Add/Edit/Details Mode Settings:                                        |
  373.    ## +---------------------------------------------------------------------------+
  374.    ##  *** set add/edit mode table properties
  375.      $em_table_properties = array("width"=>"70%");
  376.      $dgrid1->SetEditModeTableProperties($em_table_properties);
  377.    ##  *** set details mode table properties
  378.      $dm_table_properties = array("width"=>"70%");
  379.      $dgrid1->SetDetailsModeTableProperties($dm_table_properties);
  380.    ##  ***  set settings for add/edit/details modes
  381.      $table_name  = "demo_presidents";
  382.      $primary_key = "id";
  383.      $condition   = "demo_presidents.country_id = ".$dgrid->rid." ";
  384.      $dgrid1->SetTableEdit($table_name, $primary_key, $condition);
  385.    ##  *** set columns in edit mode
  386.     $em_columns = array(
  387.         "country_id"  =>array("header"=>"Country",    "type"=>"textbox",  "width"=>"160px", "req_type"=>"ri", "title"=>"Country", "readonly"=>true),      
  388.         "name"       =>array("header"=>"Name",       "type"=>"textbox",  "width"=>"140px", "req_type"=>"rt", "title"=>"Name"),
  389.         "birth_date"  =>array("header"=>"Birth Date", "type"=>"date",     "width"=>"80px", "req_type"=>"rt", "title"=>"Birth Date"),
  390.         "status"     =>array("header"=>"Status",     "type"=>"enum",     "req_type"=>"st", "width"=>"210px", "title"=>"Status", "readonly"=>false, "maxlength"=>"-1", "default"=>"", "unique"=>false, "unique_condition"=>"", "on_js_event"=>"", "source"=>"self", "view_type"=>"dropdownlist")
  391.      );
  392.      $dgrid1->SetColumnsInEditMode($em_columns);
  393.    ##  *** set foreign keys for add/edit/details modes (if there are linked tables)
  394.     $foreign_keys = array(
  395.           "country_id"=>array("table"=>"demo_countries ", "field_key"=>"id", "field_name"=>"name", "view_type"=>"dropdownbox", "condition"=>"")
  396.      );
  397.      $dgrid1->SetForeignKeysEdit($foreign_keys);
  398.  
  399.    ## +---------------------------------------------------------------------------+
  400.    ## | 8. Bind the DataGrid:                                                     |
  401.    ## +---------------------------------------------------------------------------+
  402.    ##  *** bind the DataGrid and draw it on the screen
  403.      $dgrid1->Bind();        
  404.      ob_end_flush();
  405. }
  406.  
  407. ?>