Sample 1-2. Simple PHP DG code.

    1. All modes (Add/Edit/Details/Delete/View).
    2. All features.
    3. Two DataGrids on one page.

   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.  ##  *** set needed options and create a new class instance
  20.     $debug_mode = false;        /* display SQL statements while processing */    
  21.     $messaging = true;          /* display system messages on a screen */
  22.     $unique_prefix = "f_";    /* prevent overlays - must be started with a letter */
  23.     $dgrid = new DataGrid($debug_mode, $messaging, $unique_prefix);
  24.  
  25.  ##  *** put a primary key on the first place
  26.     $sql=" SELECT "
  27.      ."demo_countries.id, "
  28.      ."demo_countries.region_id, "
  29.      ."demo_regions.name as region_name, "
  30.      ."demo_countries.name as country_name, "
  31.      ."demo_countries.description, "
  32.      ."demo_countries.picture_url, "
  33.      ."demo_countries.independent_date, "
  34.      ."FORMAT(demo_countries.population, 0) as population, "  
  35.      ."(SELECT COUNT(demo_presidents.id) FROM demo_presidents WHERE demo_presidents.country_id = demo_countries.id) as presidents, "
  36.      ." CASE WHEN demo_countries.is_democracy = 1 THEN 'Yes' ELSE 'No' END as is_democracy "
  37.      ."FROM demo_countries INNER JOIN demo_regions ON demo_countries.region_id=demo_regions.id ";
  38.  
  39.  ##  *** set data source with needed options
  40.     $default_order = array("id"=>"DESC");
  41.     $dgrid->DataSource("PEAR", "mysql", $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS, $sql, $default_order);            
  42.  
  43.  ## +---------------------------------------------------------------------------+
  44.  ## | 2. General Settings:                                                      |
  45.  ## +---------------------------------------------------------------------------+
  46.  ##  *** set encoding and collation (default: utf8/utf8_unicode_ci)
  47.     $dg_encoding = "utf8";
  48.     $dg_collation = "utf8_unicode_ci";
  49.     $dgrid->SetEncoding($dg_encoding, $dg_collation);
  50.  ##  *** set interface language (default - English)
  51.     $dg_language = "en";  
  52.     $dgrid->SetInterfaceLang($dg_language);
  53.  ##  *** set direction: "ltr" or "rtr" (default - "ltr")
  54.     $direction = "ltr";
  55.     $dgrid->SetDirection($direction);
  56.  ##  *** set layouts: 0 - tabular(horizontal) - default, 1 - columnar(vertical)
  57.     $layouts = array("view"=>0, "edit"=>1, "filter"=>1);
  58.     $dgrid->SetLayouts($layouts);
  59.  ##  *** set modes for operations ("type" => "link|button|image")
  60.  ##  *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
  61.     $modes = array(
  62.       "add"      =>array("view"=>true, "edit"=>false, "type"=>"link"),
  63.       "edit"     =>array("view"=>true, "edit"=>true,  "type"=>"link", "byFieldValue"=>""),
  64.       "cancel"  =>array("view"=>true, "edit"=>true,  "type"=>"link"),
  65.       "details" =>array("view"=>true, "edit"=>false, "type"=>"link"),
  66.       "delete"  =>array("view"=>true, "edit"=>true,  "type"=>"image")
  67.     );
  68.     $dgrid->SetModes($modes);
  69.  ##  *** allow mulirow operations
  70.     $multirow_option = true;
  71.     $dgrid->AllowMultirowOperations($multirow_option);
  72.     $multirow_operations = array(
  73.       "delete"  => array("view"=>true),
  74.       "details" => array("view"=>true)
  75.     );
  76.     $dgrid->SetMultirowOperations($multirow_operations);  
  77.  ##  *** set CSS class for datagrid
  78.  ##  *** "default" or "blue" or "gray" or "green" or your css file relative path with name
  79.     $css_class = "default";
  80.     $dgrid->SetCssClass($css_class);
  81.  ##  *** set other datagrid/s unique prefixes (if you use few datagrids on one page)
  82.  ##  *** format (in wich mode to allow processing of another datagrids)
  83.  ##  *** array("unique_prefix"=>array("view"=>true|false, "edit"=>true|false, "details"=>true|false));
  84.     $anotherDatagrids = array("fp_"=>array("view"=>false, "edit"=>true, "details"=>true));
  85.     $dgrid->SetAnotherDatagrids($anotherDatagrids);  
  86.  ##  *** set DataGrid caption
  87.     $dg_caption = "<b>My Favorite Lovely PHP DataGrid</b>";
  88.     $dgrid->SetCaption($dg_caption);
  89.  
  90.  ## +---------------------------------------------------------------------------+
  91.  ## | 3. Printing & Exporting Settings:                                         |
  92.  ## +---------------------------------------------------------------------------+
  93.  ##  *** set printing option: true(default) or false
  94.     $printing_option = true;
  95.     $dgrid->AllowPrinting($printing_option);
  96.  ##  *** set exporting option: true(default) or false
  97.     $exporting_option = false;
  98.     $dgrid->AllowExporting($exporting_option);
  99.  
  100.  ## +---------------------------------------------------------------------------+
  101.  ## | 4. Sorting & Paging Settings:                                             |
  102.  ## +---------------------------------------------------------------------------+
  103.  ##  *** set sorting option: true(default) or false
  104.     $sorting_option = true;
  105.     $dgrid->AllowSorting($sorting_option);              
  106.  ##  *** set paging option: true(default) or false
  107.     $paging_option = true;
  108.     $rows_numeration = false;
  109.     $numeration_sign = "N #";      
  110.     $dgrid->AllowPaging($paging_option, $rows_numeration, $numeration_sign);
  111.  ##  *** set paging settings
  112.     $bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
  113.     $top_paging = array();
  114.     $pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
  115.     $default_page_size = 10;
  116.     $dgrid->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size);
  117.  
  118.  ## +---------------------------------------------------------------------------+
  119.  ## | 5. Filter Settings:                                                       |
  120.  ## +---------------------------------------------------------------------------+
  121.  ##  *** set filtering option: true or false(default)
  122.     $filtering_option = true;
  123.     $dgrid->AllowFiltering($filtering_option);
  124.  ##  *** set aditional filtering settings
  125.     $fill_from_array = array("10000"=>"10000", "250000"=>"250000", "5000000"=>"5000000", "25000000"=>"25000000", "100000000"=>"100000000");
  126.     $sel_region = isset($_POST['sel_region']) ? $_POST['sel_region'] : "";
  127.     $country_condition = (!empty($sel_region)) ? "region_id=".(int)$sel_region : "";      
  128.     $filtering_fields = array(
  129.       "Region"      =>array("type"=>"enum", "view_type"=>"dropdownlist", "table"=>"demo_regions",   "field"=>"id", "field_view"=>"name", "source"=>"self", "order"=>"DESC", "default_operator"=>"=", "default"=>$sel_region, "on_js_event"=>"onchange='".$unique_prefix."_doPostBack(\"reset\", 0, \"&sel_region=\"+this.value)'"),
  130.       "Country"     =>array("type"=>"enum", "view_type"=>"dropdownlist", "table"=>"demo_countries", "field"=>"id", "field_view"=>"name", "source"=>"self", "order"=>"DESC", "default_operator"=>"=", "condition"=>$country_condition),
  131.       "Date"        =>array("type"=>"textbox", "table"=>"demo_countries", "field"=>"independent_date", "source"=>"self", "operator"=>true, "case_sensitive"=>false,  "comparison_type"=>"string"),      
  132.       "Population"  =>array("type"=>"enum", "view_type"=>"dropdownlist", "table"=>"demo_countries", "field"=>"population", "source"=>$fill_from_array, "order"=>"DESC", "operator"=>true, "case_sensitive"=>false, "comparison_type"=>"numeric")
  133.     );
  134.     $dgrid->SetFieldsFiltering($filtering_fields);
  135.  
  136.   ## +---------------------------------------------------------------------------+
  137.  ## | 6. View Mode Settings:                                                    |
  138.  ## +---------------------------------------------------------------------------+
  139.  ##  *** set view mode table properties
  140.  /// $vm_table_properties = array("width"=>"90%");
  141.  /// $dgrid->SetViewModeTableProperties($vm_table_properties);  
  142.  ##  *** set columns in view mode
  143.  ##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
  144.  ##  ***      "barchart" : number format in SELECT SQL must be equal with number format in max_value
  145.     $vm_colimns = array(
  146.       "region_name"  =>array("header"=>"Region Name",      "type"=>"label", "width"=>"130px", "align"=>"left",   "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal"),
  147.       "country_name" =>array("header"=>"Country Name",     "type"=>"linktoedit", "align"=>"left", "width"=>"130px", "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal", "summarize"=>false, "on_js_event"=>""),
  148.       "population"   =>array("header"=>"Population",       "type"=>"label", "summarize"=>true, "align"=>"right",  "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal"),
  149.       "presidents"   =>array("header"=>"Presidents",       "type"=>"label", "summarize"=>true, "align"=>"right",  "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal"),
  150.       "description"  =>array("header"=>"Short Description","type"=>"label", "align"=>"left",   "wrap"=>"wrap",   "text_length"=>"30", "case"=>"lower"),
  151.       "picture_url"  =>array("header"=>"Picture",          "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"),
  152.     );
  153.     $dgrid->SetColumnsInViewMode($vm_colimns);
  154.  
  155.  ## +---------------------------------------------------------------------------+
  156.  ## | 7. Add/Edit/Details Mode Settings:                                        |
  157.  ## +---------------------------------------------------------------------------+
  158.  ##  *** set add/edit mode table properties
  159.  /// $em_table_properties = array("width"=>"70%");
  160.  /// $dgrid->SetEditModeTableProperties($em_table_properties);
  161.  ##  *** set details mode table properties
  162.  /// $dm_table_properties = array("width"=>"70%");
  163.  /// $dgrid->SetDetailsModeTableProperties($dm_table_properties);
  164.  ##  ***  set settings for add/edit/details modes
  165.     $table_name  = "demo_countries";
  166.     $primary_key = "id";
  167.     $condition   = "";
  168.     $dgrid->SetTableEdit($table_name, $primary_key, $condition);
  169.  ##  *** set columns in edit mode
  170.    $fill_from_array = array("10000"=>"10000", "250000"=>"250000", "5000000"=>"5000000", "25000000"=>"25000000", "100000000"=>"100000000");
  171.     $em_columns = array(
  172.       "region_id"        =>array("header"=>"Region",           "type"=>"textbox",  "width"=>"210px", "req_type"=>"rt", "title"=>"Region Name"),
  173.       "name"             =>array("header"=>"Country",          "type"=>"textbox",  "width"=>"210px", "req_type"=>"ry", "title"=>"Country Name", "unique"=>true),
  174.       "description"      =>array("header"=>"Short Descr.",     "type"=>"textarea", "width"=>"210px", "req_type"=>"rt", "title"=>"Short Description", "edit_type"=>"wysiwyg", "rows"=>"7", "cols"=>"50"),
  175.       "population"       =>array("header"=>"Peoples",          "type"=>"enum",     "source"=>$fill_from_array, "view_type"=>"dropdownlist",  "width"=>"139px", "req_type"=>"ri", "title"=>"Population (Peoples)"),
  176.       "picture_url"      =>array("header"=>"Image URL",        "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"),
  177.       "is_democracy"     =>array("header"=>"Is Democracy",     "type"=>"checkbox", "req_type"=>"sy", "width"=>"210px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "true_value"=>"1", "false_value"=>"0"),        
  178.       "independent_date" =>array("header"=>"Independence Day", "type"=>"date",     "req_type"=>"rt", "width"=>"187px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "calendar_type"=>"floating"),
  179.     );
  180.     $dgrid->SetColumnsInEditMode($em_columns);
  181.  ##  *** set auto-genereted columns in edit mode
  182.  //  $auto_column_in_edit_mode = false;
  183.  //  $dgrid->SetAutoColumnsInEditMode($auto_column_in_edit_mode);
  184.  ##  *** set foreign keys for add/edit/details modes (if there are linked tables)
  185.  ##  *** Ex.: "condition"=>"TableName_1.FieldName < 2 OR TableName_1.FieldName > 10 "
  186.  ##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
  187.   $foreign_keys = array(
  188.       "region_id"=>array("table"=>"demo_regions", "field_key"=>"id", "field_name"=>"name", "view_type"=>"dropdownlist", "order_by_field"=>"name", "order_type"=>"ASC")
  189.    );
  190.    $dgrid->SetForeignKeysEdit($foreign_keys);
  191.  
  192.  ## +---------------------------------------------------------------------------+
  193.  ## | 8. Bind the DataGrid:                                                     |
  194.  ## +---------------------------------------------------------------------------+
  195.  ##  *** bind the DataGrid and draw it on the screen
  196.    $dgrid->Bind();        
  197.     ob_end_flush();
  198.  ##
  199.  ################################################################################  
  200.  
  201.   // if we in EDIT mode of the first datagrid
  202.   if(isset($_GET["f_mode"]) && (($_GET["f_mode"] == "edit") || ($_GET["f_mode"] == "details"))){
  203.      
  204.    ## +---------------------------------------------------------------------------+
  205.    ## | 1. Creating & Calling:                                                    |
  206.    ## +---------------------------------------------------------------------------+
  207.  
  208.       ob_start();
  209.    ##  *** put a primary key on the first place
  210.       $sql=" SELECT "
  211.        ."demo_presidents.id, "
  212.        ."demo_presidents.country_id, "
  213.        ."demo_presidents.name, "
  214.        ."demo_presidents.birth_date, "
  215.        ."demo_presidents.status "
  216.        ."FROM demo_presidents INNER JOIN demo_countries ON demo_presidents.country_id=demo_countries.id "      
  217.        ."WHERE demo_presidents.country_id = ".$dgrid->rid." ";
  218.    ##  *** set needed options and create a new class instance
  219.       $debug_mode = false;        /* display SQL statements while processing */    
  220.       $messaging = true;          /* display system messages on a screen */
  221.       $unique_prefix = "fp_";    /* prevent overlays - must be started with a letter */
  222.       $dgrid1 = new DataGrid($debug_mode, $messaging, $unique_prefix);
  223.    ##  *** set data source with needed options
  224.       $default_order = array("id"=>"DESC");
  225.       $dgrid1->DataSource("PEAR", "mysql", $DB_HOST, $DB_NAME, $DB_USER, $DB_PASS, $sql, $default_order);            
  226.  
  227.    ## +---------------------------------------------------------------------------+
  228.    ## | 2. General Settings:                                                      |
  229.    ## +---------------------------------------------------------------------------+
  230.    ##  *** set encoding and collation (default: utf8/utf8_unicode_ci)
  231.       $dg_encoding = "utf8";
  232.       $dg_collation = "utf8_unicode_ci";
  233.       $dgrid1->SetEncoding($dg_encoding, $dg_collation);
  234.    ##  *** set interface language (default - English)
  235.    ##  *** (en) - English     (de) - German     (se) Swedish     (hr) - Bosnian/Croatian
  236.    ##  *** (hu) - Hungarian   (es) - Espanol    (ca) - Catala    (fr) - Francais
  237.    ##  *** (nl) - Netherlands/"Vlaams"(Flemish) (it) - Italiano  (pl) - Polish
  238.    ##  *** (ch) - Chinese     (sr) - Serbian
  239.       $dg_language = "en";  
  240.       $dgrid1->SetInterfaceLang($dg_language);
  241.    ##  *** set direction: "ltr" or "rtr" (default - "ltr")
  242.       $direction = "ltr";
  243.       $dgrid1->SetDirection($direction);
  244.    ##  *** set layouts: 0 - tabular(horizontal) - default, 1 - columnar(vertical)
  245.       $layouts = array("view"=>0, "edit"=>0, "filter"=>1);
  246.       $dgrid1->SetLayouts($layouts);
  247.    ##  *** set modes for operations ("type" => "link|button|image")
  248.    ##  *** "byFieldValue"=>"fieldName" - make the field to be a link to edit mode page
  249.       if($_GET["f_mode"] == "edit"){    
  250.         $modes = array(
  251.           "add"=>array("view"=>true, "edit"=>false, "type"=>"link"),
  252.           "edit"=>array("view"=>true, "edit"=>true, "type"=>"link", "byFieldValue"=>""),
  253.           "cancel"=>array("view"=>true, "edit"=>true, "type"=>"link"),
  254.           "details"=>array("view"=>false, "edit"=>false, "type"=>"link"),
  255.           "delete"=>array("view"=>true, "edit"=>false, "type"=>"image")
  256.         );
  257.       }else{
  258.         $modes = array(
  259.           "add"=>array("view"=>false, "edit"=>false, "type"=>"link"),
  260.           "edit"=>array("view"=>false, "edit"=>false, "type"=>"link", "byFieldValue"=>""),
  261.           "cancel"=>array("view"=>false, "edit"=>true, "type"=>"link"),
  262.           "details"=>array("view"=>false, "edit"=>false, "type"=>"link"),
  263.           "delete"=>array("view"=>false, "edit"=>false, "type"=>"image")
  264.         );
  265.       }
  266.       $dgrid1->SetModes($modes);
  267.    ##  *** allow mulirow operations
  268.       $multirow_option = true;
  269.       $dgrid1->AllowMultirowOperations($multirow_option);
  270.       $multirow_operations = array(
  271.         "edit"    => array("view"=>false),
  272.         "delete"  => array("view"=>true),
  273.         "details" => array("view"=>true),
  274.       );
  275.       $dgrid1->SetMultirowOperations($multirow_operations);  
  276.    ##  *** set CSS class for datagrid
  277.    ##  *** "default" or "blue" or "gray" or "green" or your css file relative path with name
  278.       $css_class = "default";
  279.       $dgrid1->SetCssClass($css_class);
  280.    ##  *** set other datagrid/s unique prefixes (if you use few datagrids on one page)
  281.    ##  *** format (in wich mode to allow processing of another datagrids)
  282.    ##  *** array("unique_prefix"=>array("view"=>true|false, "edit"=>true|false, "details"=>true|false));
  283.       $anotherDatagrids = array("f_"=>array("view"=>true, "edit"=>true, "details"=>true));
  284.       $dgrid1->SetAnotherDatagrids($anotherDatagrids);  
  285.    ##  *** set DataGrid caption
  286.       $dg_caption = "Presidents";
  287.       $dgrid1->SetCaption($dg_caption);
  288.  
  289.    ## +---------------------------------------------------------------------------+
  290.    ## | 3. Printing & Exporting Settings:                                         |
  291.    ## +---------------------------------------------------------------------------+
  292.    ##  *** set printing option: true(default) or false
  293.       $printing_option = false;
  294.       $dgrid1->AllowPrinting($printing_option);
  295.    ##  *** set exporting option: true(default) or false
  296.       $exporting_option = false;
  297.       $dgrid1->AllowExporting($exporting_option);
  298.  
  299.    ## +---------------------------------------------------------------------------+
  300.    ## | 4. Sorting & Paging Settings:                                             |
  301.    ## +---------------------------------------------------------------------------+
  302.    ##  *** set sorting option: true(default) or false
  303.       $sorting_option = true;
  304.       $dgrid1->AllowSorting($sorting_option);              
  305.    ##  *** set paging option: true(default) or false
  306.       $paging_option = true;
  307.       $rows_numeration = false;
  308.       $numeration_sign = "N #";      
  309.       $dgrid1->AllowPaging($paging_option, $rows_numeration, $numeration_sign);
  310.    ##  *** set paging settings
  311.       $bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
  312.       $top_paging = array();
  313.       $pages_array = array("10"=>"10", "25"=>"25", "50"=>"50", "100"=>"100", "250"=>"250", "500"=>"500", "1000"=>"1000");
  314.       $default_page_size = 10;
  315.       $dgrid1->SetPagingSettings($bottom_paging, $top_paging, $pages_array, $default_page_size);
  316.  
  317.    ## +---------------------------------------------------------------------------+
  318.    ## | 6. View Mode Settings:                                                    |
  319.    ## +---------------------------------------------------------------------------+
  320.    ##  *** set view mode table properties
  321.       $vm_table_properties = array("width"=>"70%");
  322.       $dgrid1->SetViewModeTableProperties($vm_table_properties);  
  323.    ##  *** set columns in view mode
  324.    ##  *** Ex.: "on_js_event"=>"onclick='alert(\"Yes!!!\");'"
  325.    ##  ***      "barchart" : number format in SELECT SQL must be equal with number format in max_value
  326.       $vm_colimns = array(
  327.         "name"       =>array("header"=>"Name",        "type"=>"label", "align"=>"left",  "wrap"=>"wrap",   "text_length"=>"20", "case"=>"normal"),
  328.         "birth_date" =>array("header"=>"Birth Date",  "type"=>"label", "align"=>"center",  "wrap"=>"nowrap", "text_length"=>"-1", "case"=>"normal"),
  329.         "status"     =>array("header"=>"Status",      "type"=>"label", "align"=>"center",  "wrap"=>"nowrap", "text_length"=>"30", "case"=>"normal")
  330.       );
  331.       $dgrid1->SetColumnsInViewMode($vm_colimns);
  332.    ##  *** set auto-genereted columns in view mode
  333.    // $auto_column_in_view_mode = false;
  334.    // $dgrid1->SetAutoColumnsInViewMode($auto_column_in_view_mode);
  335.  
  336.    ## +---------------------------------------------------------------------------+
  337.    ## | 7. Add/Edit/Details Mode Settings:                                        |
  338.    ## +---------------------------------------------------------------------------+
  339.    ##  *** set add/edit mode table properties
  340.       $em_table_properties = array("width"=>"70%");
  341.       $dgrid1->SetEditModeTableProperties($em_table_properties);
  342.    ##  *** set details mode table properties
  343.       $dm_table_properties = array("width"=>"70%");
  344.       $dgrid1->SetDetailsModeTableProperties($dm_table_properties);
  345.    ##  ***  set settings for add/edit/details modes
  346.       $table_name  = "demo_presidents";
  347.       $primary_key = "id";
  348.       $condition   = "demo_presidents.country_id = ".$dgrid->rid." ";
  349.       $dgrid1->SetTableEdit($table_name, $primary_key, $condition);
  350.    ##  *** set columns in edit mode
  351.       $em_columns = array(
  352.         "country_id"  =>array("header"=>"Country",    "type"=>"textbox",  "width"=>"160px", "req_type"=>"ri", "title"=>"Country", "readonly"=>true),      
  353.         "name"       =>array("header"=>"Name",       "type"=>"textbox",  "width"=>"140px", "req_type"=>"rt", "title"=>"Name"),
  354.         "birth_date"  =>array("header"=>"Birth Date", "type"=>"date",     "req_type"=>"rt", "width"=>"80px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "calendar_type"=>"floating"),
  355.         "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")
  356.       );
  357.       $dgrid1->SetColumnsInEditMode($em_columns);
  358.    ##  *** set auto-genereted columns in edit mode
  359.    // $auto_column_in_edit_mode = false;
  360.    // $dgrid1->SetAutoColumnsInEditMode($auto_column_in_edit_mode);
  361.    ##  *** set foreign keys for add/edit/details modes (if there are linked tables)
  362.       $foreign_keys = array(
  363.             "country_id"=>array("table"=>"demo_countries", "field_key"=>"id", "field_name"=>"name", "view_type"=>"dropdownlist", "condition"=>"")
  364.       );
  365.       $dgrid1->SetForeignKeysEdit($foreign_keys);
  366.  
  367.    ## +---------------------------------------------------------------------------+
  368.    ## | 8. Bind the DataGrid:                                                     |
  369.    ## +---------------------------------------------------------------------------+
  370.    ##  *** bind the DataGrid and draw it on the screen
  371.       $dgrid1->Bind();        
  372.       ob_end_flush();
  373.     ################################################################################  
  374.  }  
  375.