PHP DataGrid is still in the development phase, so please...
1. Make sure, that every table in the database you use has a primary key!
2. In "SELECT" SQL statement put this key field at the first place.
3. Don't use in your "SELECT" SQL statement "ORDER BY" option - it's ordered by primary key automaticly.
Small bug in version 3.x.x:
See forum discussing here.
Saturday, October 28, 2006
New version 3.1.0 of PHP DataGrid
New version 3.1.0 of PHP DataGrid is available for downloading from now.
General features of this version:
-------------------------
- View mode
-- Tabular layout
-- Columnar layout
- Details mode
-- Columnar layout
- Add new mode
- Edit mode
-- Tabular layout
-- Columnar layout
- Delete mode
- Automatic validation
-- Client side
- Columns sorting
- Fields filtering
- Paging
-- current/total pages selector
-- pager
-- page size drop-down box
- Embedded css templates
To download a new version click here.
To see Live Demo click here.
The new version comes in .rar archive that contains following files:
- Datagrid folder
-- datagrid.class.php
-- form.scripts.js
-- calendar.js
-- cal.gif
- Example folder
-- code_example.php
-- database_example(SQL).txt
- lisence.txt
- readme.txt
- documentation.txt
Friday, October 27, 2006
PHP DataGrid v.3.x.x
--------------------------------------------------------------
To download version 3.2.0 click here.
This version changes:
- Added
-- ability to define array of page sizes
-- case sensitivity (filtering mode)
-- ability to define search field to be a dropdown box (filtering mode)
-- ability to add optional column in datagrid by editing SELECT SQL statement
-- new css template (default)
-- ability to define column data to be a link on edit mode page
("linktoview" in setColumnsInViewMode())
- Improved:
-- setModes()
-- css class "default"
-- working with $_REQUEST vars
- Fixed bugs:
-- in filtering mode
-- in tabular layout drawing
-- in columnar layout drawing
-- in paging after search
-- empty table bug
To download version 3.1.0 click here.
--------------------------------------------------------------
PHP DataGrid documentation for version 3.x.x
--------------------------------------------------------------
1. System Requirements
------------------------------
PHP DataGrid is operating system independent. You get it works
on both Linux and Windows. You need following components are
installed:
- PHP 4.0 script engine or later
- Apache 1.3 or above
- mySQL 3.23 or above
2. Lisencing
------------------------------
GNU GPL. See the Lisence.txt file.
3. Installation
------------------------------
<? require_once($PHP_DATAGRID_FOLDER_PATH."/datagrid.class.php") ?>
Where $PHP_DATAGRID_FOLDER_PATH - is a path to the folder
named "datagrid" stored on your server.
3. General Features
------------------------------
- CSS emb.templates
- Column sorting
- Filtering
- Pagging
- Automatic validation
-- Client side
- View mode
-- Tabular layout
-- Columnar layout
- Details mode
-- Columnar layout
- Add new mode
- Edit mode
-- Tabular layout
-- Columnar layout
- Delete mode
To see example of code click here.
To download version 3.2.0 click here.
To download version 3.1.0 click here.
--------------------------------------------------------------
Thursday, October 26, 2006
Code example for PHP DataGrid v.3.x.x
<?
########################################
## Creating & Calling
## --------------------------------------------------------
require_once('datagrid/datagrid.class.php');
##
## *** creating variables that we need for database connection
$DB_USER='phpbuilder_dgrid'; // usually like this: prefix_name
$DB_PASS='12345'; // must be already enscrypted
$DB_HOST='db5.awardspace.com'; // often localhost
$DB_NAME='phpbuilder_dgrid'; // usually like this: prefix_name
ob_start();
$db_conn = mysql_connect($DB_HOST,$DB_USER,$DB_PASS);
mysql_select_db($DB_NAME,$db_conn);
## *** put primary key on the first place
$sql=" SELECT "
."tblCountries.CountryID, "
."tblRegions.Name as Region, "
."tblCountries.Name, "
."tblCountries.Description, "
."tblCountries.Population, "
."tblCountries.PictureURL, "
."tblDemocracy.description as is_democracy "
."FROM tblCountries INNER JOIN tblRegions ON tblCountries.RegionID=tblRegions.RegionID "
."LEFT OUTER JOIN tblDemocracy ON tblCountries.is_democracy=tblDemocracy.did ";
$dgrid = new DataGrid();
$dgrid->dataSource($db_conn, $sql);
##
## General Settings
## --------------------------------------------------------
## *** set unique prefix
$u_prefix = "_abc";
$dgrid->setUniqueNames($u_prefix);
## *** set direction: "ltr" or "rtr"
$direction = "ltr";
$dgrid->setDirection($direction);
## *** set layouts: 0 - tabular(horizontal) - default, 1 - columnar(vertical)
$layouts = array("view"=>0, "edit"=>1, "filter"=>1);
$dgrid->setLayouts($layouts);
## *** set other modes
$modes = array(
"add"=>array("view"=>true, "edit"=>false),
"edit"=>array("view"=>true, "edit"=>true, "byfield"=>""),
"cancel"=>array("allow"=>true,"view"=>true, "edit"=>true),
"details"=>array("view"=>true, "edit"=>false),
"delete"=>array("view"=>true, "edit"=>true)
);
$dgrid->setModes($modes);
## *** set nowrap attributes for all columns
$wrap = "nowrap";
$dgrid->setColumnsNoWrap($wrap);
## *** set CSS class for datagrid: "default" or "like adwords" or "salomon"
$css_class = "default";
$dgrid->setCssClass($css_class);
##
## Sorting & Paging Settings:
## ---------
## *** set sorting option: true(default) or false
$s_option = true;
$dgrid->allowSorting($s_option);
## *** set paging option: true(default) or false
$p_option = true;
$dgrid->allowPaging($p_option);
## *** 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();
$dgrid->setPagingSettings($bottom_paging, $top_paging);
##
## Filter Settings
## --------------------------------------------------------
## *** set filtering option: true or false(default)
$f_option = true;
$dgrid->allowFiltering(true);
## *** set fileds in filtering mode:
$f_fileds = array(
"Country"=>array("table"=>"tblCountries", "field"=>"Name", "operator"=>true),
"Region"=>array("table"=>"tblRegions", "field"=>"Name", "operator"=>true),
"Population"=>array("table"=>"tblCountries", "field"=>"Population", "operator"=>true)
);
$dgrid->setFieldsFiltering($f_fileds);
##
## View Mode Settings:
## --------------------------------------------------------
## *** set columns in view mode
$vm_colimns = array(
"Region"=>array("header"=>"Region Name","type"=>"label", "text_length"=>"-1"),
"Name"=>array("header"=>"Country Name","type"=>"label", "text_length"=>"-1"),
"Population"=>array("header"=>"Population","type"=>"label", "text_length"=>"-1"),
"Description"=>array("header"=>"Short Description","type"=>"label", "text_length"=>"30"),
"PictureURL"=>array("header"=>"Picture","type"=>"link", "field"=>"PictureURL", "prefix"=>"http://", "target"=>"_new", "text_length"=>"-1")
);
$dgrid->setColumnsInViewMode($vm_colimns);
##
## Edit Mode settings:
## --------------------------------------------------------
## *** set settings for details mode
$table_name = "tblCountries";
$primary_key = "CountryID";
$dgrid->setTableEdit($table_name, $primary_key);
## *** set columns in edit mode
$em_columns = array(
"RegionID" =>array("header"=>"Region","type"=>"textbox","req_type"=>"rt", "title"=>"Region Name"),
"Name" =>array("header"=>"Country","type"=>"textbox","req_type"=>"ry", "title"=>"Country Name"),
"Description" =>array("header"=>"Short Descr.","type"=>"textarea","req_type"=>"rt", "title"=>"Short Description"),
"Population" =>array("header"=>"Peoples","type"=>"textbox","req_type"=>"ri", "title"=>"Population(Peoples)"),
"PictureURL" =>array("header"=>"ImageURL","type"=>"textbox","req_type"=>"rt", "title"=>"Image URL"),
"is_democracy" =>array("header"=>"IsDemocracy","type"=>"textbox","req_type"=>"sy", "title"=>"Is Democraty")
);
$dgrid->setColumnsInEditMode($em_columns);
## *** set foreign keys for edit mode
$f_keys = array(
"RegionID"=>array("table"=>"tblRegions", "field_key"=>"RegionID", "field_name"=>"Name", "view_type"=>"combobox"),
"is_democracy"=>array("table"=>"tblDemocracy ", "field_key"=>"did", "field_name"=>"description", "view_type"=>"radiobutton")
);
$dgrid->setForeignKeysEdit($f_keys);
##
## Bind the DataGrid:
## --------------------------------------------------------
## *** set debug mode & messaging options
$debug_mode = false;
$messaging = true;
$dgrid->bind($debug_mode, $messaging);
ob_end_flush();
##
########################################
?>
########################################
## Creating & Calling
## --------------------------------------------------------
require_once('datagrid/datagrid.class.php');
##
## *** creating variables that we need for database connection
$DB_USER='phpbuilder_dgrid'; // usually like this: prefix_name
$DB_PASS='12345'; // must be already enscrypted
$DB_HOST='db5.awardspace.com'; // often localhost
$DB_NAME='phpbuilder_dgrid'; // usually like this: prefix_name
ob_start();
$db_conn = mysql_connect($DB_HOST,$DB_USER,$DB_PASS);
mysql_select_db($DB_NAME,$db_conn);
## *** put primary key on the first place
$sql=" SELECT "
."tblCountries.CountryID, "
."tblRegions.Name as Region, "
."tblCountries.Name, "
."tblCountries.Description, "
."tblCountries.Population, "
."tblCountries.PictureURL, "
."tblDemocracy.description as is_democracy "
."FROM tblCountries INNER JOIN tblRegions ON tblCountries.RegionID=tblRegions.RegionID "
."LEFT OUTER JOIN tblDemocracy ON tblCountries.is_democracy=tblDemocracy.did ";
$dgrid = new DataGrid();
$dgrid->dataSource($db_conn, $sql);
##
## General Settings
## --------------------------------------------------------
## *** set unique prefix
$u_prefix = "_abc";
$dgrid->setUniqueNames($u_prefix);
## *** set direction: "ltr" or "rtr"
$direction = "ltr";
$dgrid->setDirection($direction);
## *** set layouts: 0 - tabular(horizontal) - default, 1 - columnar(vertical)
$layouts = array("view"=>0, "edit"=>1, "filter"=>1);
$dgrid->setLayouts($layouts);
## *** set other modes
$modes = array(
"add"=>array("view"=>true, "edit"=>false),
"edit"=>array("view"=>true, "edit"=>true, "byfield"=>""),
"cancel"=>array("allow"=>true,"view"=>true, "edit"=>true),
"details"=>array("view"=>true, "edit"=>false),
"delete"=>array("view"=>true, "edit"=>true)
);
$dgrid->setModes($modes);
## *** set nowrap attributes for all columns
$wrap = "nowrap";
$dgrid->setColumnsNoWrap($wrap);
## *** set CSS class for datagrid: "default" or "like adwords" or "salomon"
$css_class = "default";
$dgrid->setCssClass($css_class);
##
## Sorting & Paging Settings:
## ---------
## *** set sorting option: true(default) or false
$s_option = true;
$dgrid->allowSorting($s_option);
## *** set paging option: true(default) or false
$p_option = true;
$dgrid->allowPaging($p_option);
## *** 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();
$dgrid->setPagingSettings($bottom_paging, $top_paging);
##
## Filter Settings
## --------------------------------------------------------
## *** set filtering option: true or false(default)
$f_option = true;
$dgrid->allowFiltering(true);
## *** set fileds in filtering mode:
$f_fileds = array(
"Country"=>array("table"=>"tblCountries", "field"=>"Name", "operator"=>true),
"Region"=>array("table"=>"tblRegions", "field"=>"Name", "operator"=>true),
"Population"=>array("table"=>"tblCountries", "field"=>"Population", "operator"=>true)
);
$dgrid->setFieldsFiltering($f_fileds);
##
## View Mode Settings:
## --------------------------------------------------------
## *** set columns in view mode
$vm_colimns = array(
"Region"=>array("header"=>"Region Name","type"=>"label", "text_length"=>"-1"),
"Name"=>array("header"=>"Country Name","type"=>"label", "text_length"=>"-1"),
"Population"=>array("header"=>"Population","type"=>"label", "text_length"=>"-1"),
"Description"=>array("header"=>"Short Description","type"=>"label", "text_length"=>"30"),
"PictureURL"=>array("header"=>"Picture","type"=>"link", "field"=>"PictureURL", "prefix"=>"http://", "target"=>"_new", "text_length"=>"-1")
);
$dgrid->setColumnsInViewMode($vm_colimns);
##
## Edit Mode settings:
## --------------------------------------------------------
## *** set settings for details mode
$table_name = "tblCountries";
$primary_key = "CountryID";
$dgrid->setTableEdit($table_name, $primary_key);
## *** set columns in edit mode
$em_columns = array(
"RegionID" =>array("header"=>"Region","type"=>"textbox","req_type"=>"rt", "title"=>"Region Name"),
"Name" =>array("header"=>"Country","type"=>"textbox","req_type"=>"ry", "title"=>"Country Name"),
"Description" =>array("header"=>"Short Descr.","type"=>"textarea","req_type"=>"rt", "title"=>"Short Description"),
"Population" =>array("header"=>"Peoples","type"=>"textbox","req_type"=>"ri", "title"=>"Population(Peoples)"),
"PictureURL" =>array("header"=>"ImageURL","type"=>"textbox","req_type"=>"rt", "title"=>"Image URL"),
"is_democracy" =>array("header"=>"IsDemocracy","type"=>"textbox","req_type"=>"sy", "title"=>"Is Democraty")
);
$dgrid->setColumnsInEditMode($em_columns);
## *** set foreign keys for edit mode
$f_keys = array(
"RegionID"=>array("table"=>"tblRegions", "field_key"=>"RegionID", "field_name"=>"Name", "view_type"=>"combobox"),
"is_democracy"=>array("table"=>"tblDemocracy ", "field_key"=>"did", "field_name"=>"description", "view_type"=>"radiobutton")
);
$dgrid->setForeignKeysEdit($f_keys);
##
## Bind the DataGrid:
## --------------------------------------------------------
## *** set debug mode & messaging options
$debug_mode = false;
$messaging = true;
$dgrid->bind($debug_mode, $messaging);
ob_end_flush();
##
########################################
?>
Friday, October 13, 2006
The blog's Forum
Dear readers and visitors!
The Blog's forum is created to help Me and You to discuss any themes that related to PHP DataGrid script. If your question is about PHP DataGrid - please, leave it on the blog's Forum. It will really help me to prevent to get twice same answers.
Thanks :)
The Blog's forum is created to help Me and You to discuss any themes that related to PHP DataGrid script. If your question is about PHP DataGrid - please, leave it on the blog's Forum. It will really help me to prevent to get twice same answers.
Thanks :)
Monday, October 09, 2006
New version 2.1.0 of PHP DataGrid
New version 2.1.0 of PHP DataGrid is available for downloading from now.
Features of this version:
-------------------------
- View mode
-- Tabular layout
-- Columnar layout
- Details mode
-- Columnar layout
- Columns sorting
- Fields Filtering
- Paging
-- current/total pages selector
-- pager
-- page size drop-down box
- Embedded css templates
To download a new version click here.
To see Live Demo click here.
The new version comes in .rar archive that includes following files:
- datagrid.class.php
- example.php
- lisence.txt
- readme.txt
- documentation.txt
- SQL.txt
Features of this version:
-------------------------
- View mode
-- Tabular layout
-- Columnar layout
- Details mode
-- Columnar layout
- Columns sorting
- Fields Filtering
- Paging
-- current/total pages selector
-- pager
-- page size drop-down box
- Embedded css templates
To download a new version click here.
To see Live Demo click here.
The new version comes in .rar archive that includes following files:
- datagrid.class.php
- example.php
- lisence.txt
- readme.txt
- documentation.txt
- SQL.txt
Sunday, October 08, 2006
PHP DataGrid v.2.x.x
--------------------------------------------------------------
To download version 2.1.0 click here.
--------------------------------------------------------------
PHP DataGrid documentation for version 2.x.x
--------------------------------------------------------------
1. System Requirements
------------------------------
PHP DataGrid is operating system independent. You get it works on both Linux and
Windows. You need following components are installed:
- PHP 4.0 script engine or later
- Apache 1.3 or above
- mySQL 3.23 or above
2. Lisencing
------------------------------
See the Lisence.txt file.
3. Installation
------------------------------
<? require_once($PHP_DATAGRID_FILE_PATH."/datagrid.class") ?>
Where $PHP_DATAGRID_FILE_PATH - is a file path where PHPDataGrid stored on your server.
3. Features
------------------------------
- View mode
-- Tabular layout
-- Columnar layout
- Details mode
-- Columnar layout
- Columns sorting
- Fields Filtering
- Paging
-- current/total pages selector
-- pager
-- page size drop-down box
- Embedded css templates
To see example of code click here.
To download version 2.1.0 click here.
--------------------------------------------------------------
Saturday, October 07, 2006
Code example for PHP DataGrid v.2.x.x
We have 3 tables:
-- --------------------------------------------------------
--
-- Table structure for table `tblRegions`
--
CREATE TABLE `tblRegions` (
`RegionID` tinyint(3) unsigned NOT NULL auto_increment,
`Name` varchar(20) NOT NULL default '',
PRIMARY KEY (`RegionID`)
) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
-- --------------------------------------------------------
--
-- Table structure for table `tblCountries`
--
CREATE TABLE `tblCountries` (
`CountryID` tinyint(3) unsigned NOT NULL auto_increment,
`RegionID` tinyint(3) unsigned NOT NULL default '0',
`Name` varchar(50) NOT NULL default '',
`Description` varchar(255) NOT NULL default '',
`Population` double unsigned NOT NULL default '0',
`PictureURL` varchar(100) NOT NULL default '',
`is_democracy` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`CountryID`)
) ENGINE=MyISAM AUTO_INCREMENT=228 DEFAULT CHARSET=latin1 AUTO_INCREMENT=228 ;
-- --------------------------------------------------------
--
-- Table structure for table `tblDemocracy`
--
CREATE TABLE `tblDemocracy` (
`did` int(10) unsigned NOT NULL auto_increment,
`description` varchar(20) NOT NULL default '',
PRIMARY KEY (`did`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
The code example:
<?
require_once('datagrid.class.php');
// Creating & Calling
// --------------------------------------------------------------------------------- ob_start();
$DB_USER='username'; // usually like this: prefix_username
$DB_PASS='12345'; // must be already enscrypted
$DB_HOST='localhost'; // often localhost
$DB_NAME='dbname'; // usually like this: prefix_dbname
$db_conn=mysql_connect($DB_HOST,$DB_USER,$DB_PASS); mysql_select_db($DB_NAME,$db_conn);
$sql=" SELECT "
."tblCountries.CountryID, "
."tblCountries.Name, "
."tblCountries.Description, "
."tblCountries.Population, "
."tblCountries.PictureURL, "
."tblRegions.Name as Region, "
."tblDemocracy.description as is_democracy "
."FROM tblCountries INNER JOIN tblRegions ON
tblCountries.RegionID=tblRegions.RegionID "
."LEFT OUTER JOIN tblDemocracy ON tblCountries.is_democracy=tblDemocracy.did ";
$dgrid = new DataGrid();
$dgrid->dataSourse($db_conn, $sql);
// General Settings
// ---------
/*** set unique prefix, ex.: $unames = "_abc" */
$dgrid->setUniqueNames("_abc");
/*** set layouts, ex.: $layouts = array("view"=>0) where 0-tabular(default), 1-columnar */
$dgrid->setLayouts(array("view"=>0));
/*** set other modes */
$dgrid->setModes(array("details"=>array("view"=>true)));
/*** set for all columns, ex.: $wrap = "nowrap" */
$dgrid->setColumnsNoWrap("nowrap");
/*** set CSS class for datagrid, ex.: $class = "default"/"Like Adwords"/"salomon"/ */
$dgrid->setCssClass("default");
// Sorting & Paging Settings:
// ---------
/*** set sorting option, ex.: $s_option = true(default)/false */
$dgrid->allowSorting(true);
/*** set paging option, ex.: $p_option = true(default)/false */
$dgrid->allowPaging(true);
/*** set paging settings */
$top_paging = array();
$bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
$dgrid->setPagingSettings($bottom_paging, $top_paging);
// Filtering Settings
// ---------
/*** $option: true/false; default - false */
$dgrid->allowFiltering(true);
/*** set fileds for filtering */
$f_fields = array(
"Country"=>array("table"=>"tblCountries", "field"=>"Name"),
"Region"=>array("table"=>"tblRegions", "field"=>"Name"),
"Democracy"=>array("table"=>"tblDemocraty", "field"=>"description")
);
$dgrid->setFieldsFiltering($f_fields);
// View Mode Settings:
// ---------
/*** set columns in view mode */
$vm_columns = array(
"Name" =>array("header"=>"Country", "type"=>"label"),
"Region" =>array("header"=>"Region", "type"=>"label"),
"Description" =>array("header"=>"Short Descr.", "type"=>"label"),
"Population" =>array("header"=>"Peoples", "type"=>"label"),
"PictureURL" =>array("header"=>"ImageURL", "type"=>"link", "href"=>"www.yahoo.com", "target"=>"_new"),
"is_democracy" =>array("header"=>"IsDemocracy", "type"=>"label")
);
$dgrid->setColumnsInViewMode($vm_columns);
// Details Mode settings:
// ------------------
/*** set settings for details mode */
$table_name = "tblCountries";
$primary_key = "CountryID";
$dgrid->setTableEdit($table_name, $primary_key);
/*** set columns in details mode */
$e_columns = array(
"RegionID" =>array("header"=>"Region","type"=>"textbox"),
"Name" =>array("header"=>"Country","type"=>"textarea"),
"Description" =>array("header"=>"Short Descr.","type"=>"date"),
"Population" =>array("header"=>"Peoples","type"=>"textbox"),
"PictureURL" =>array("header"=>"ImageURL","type"=>"textbox"),
"is_democracy" =>array("header"=>"IsDemocracy","type"=>"textbox")
);
$dgrid->setColumnsInEditMode($e_columns);
/*** set foreign keys for details mode table */
$f_keys = array(
"RegionID"=>array("table"=>"tblRegions", "field_key"=>"RegionID", "field_name"=>"Name"),
"is_democraty"=>array("table"=>"tblDemocraty ", "field_key"=>"did", "field_name"=>"description")
);
$dgrid->setForeignKeysEdit($f_keys);
// Bind the DataGrid:
// ---------
/*** set debug mode & messaging options */
$debug_mode = false;
$messaging = false;
$dgrid->bind($debug_mode, $messaging);
ob_end_flush();
?>
-- --------------------------------------------------------
--
-- Table structure for table `tblRegions`
--
CREATE TABLE `tblRegions` (
`RegionID` tinyint(3) unsigned NOT NULL auto_increment,
`Name` varchar(20) NOT NULL default '',
PRIMARY KEY (`RegionID`)
) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;
-- --------------------------------------------------------
--
-- Table structure for table `tblCountries`
--
CREATE TABLE `tblCountries` (
`CountryID` tinyint(3) unsigned NOT NULL auto_increment,
`RegionID` tinyint(3) unsigned NOT NULL default '0',
`Name` varchar(50) NOT NULL default '',
`Description` varchar(255) NOT NULL default '',
`Population` double unsigned NOT NULL default '0',
`PictureURL` varchar(100) NOT NULL default '',
`is_democracy` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`CountryID`)
) ENGINE=MyISAM AUTO_INCREMENT=228 DEFAULT CHARSET=latin1 AUTO_INCREMENT=228 ;
-- --------------------------------------------------------
--
-- Table structure for table `tblDemocracy`
--
CREATE TABLE `tblDemocracy` (
`did` int(10) unsigned NOT NULL auto_increment,
`description` varchar(20) NOT NULL default '',
PRIMARY KEY (`did`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
The code example:
<?
require_once('datagrid.class.php');
// Creating & Calling
// --------------------------------------------------------------------------------- ob_start();
$DB_USER='username'; // usually like this: prefix_username
$DB_PASS='12345'; // must be already enscrypted
$DB_HOST='localhost'; // often localhost
$DB_NAME='dbname'; // usually like this: prefix_dbname
$db_conn=mysql_connect($DB_HOST,$DB_USER,$DB_PASS); mysql_select_db($DB_NAME,$db_conn);
$sql=" SELECT "
."tblCountries.CountryID, "
."tblCountries.Name, "
."tblCountries.Description, "
."tblCountries.Population, "
."tblCountries.PictureURL, "
."tblRegions.Name as Region, "
."tblDemocracy.description as is_democracy "
."FROM tblCountries INNER JOIN tblRegions ON
tblCountries.RegionID=tblRegions.RegionID "
."LEFT OUTER JOIN tblDemocracy ON tblCountries.is_democracy=tblDemocracy.did ";
$dgrid = new DataGrid();
$dgrid->dataSourse($db_conn, $sql);
// General Settings
// ---------
/*** set unique prefix, ex.: $unames = "_abc" */
$dgrid->setUniqueNames("_abc");
/*** set layouts, ex.: $layouts = array("view"=>0) where 0-tabular(default), 1-columnar */
$dgrid->setLayouts(array("view"=>0));
/*** set other modes */
$dgrid->setModes(array("details"=>array("view"=>true)));
/*** set for all columns, ex.: $wrap = "nowrap" */
$dgrid->setColumnsNoWrap("nowrap");
/*** set CSS class for datagrid, ex.: $class = "default"/"Like Adwords"/"salomon"/ */
$dgrid->setCssClass("default");
// Sorting & Paging Settings:
// ---------
/*** set sorting option, ex.: $s_option = true(default)/false */
$dgrid->allowSorting(true);
/*** set paging option, ex.: $p_option = true(default)/false */
$dgrid->allowPaging(true);
/*** set paging settings */
$top_paging = array();
$bottom_paging = array("results"=>true, "results_align"=>"left", "pages"=>true, "pages_align"=>"center", "page_size"=>true, "page_size_align"=>"right");
$dgrid->setPagingSettings($bottom_paging, $top_paging);
// Filtering Settings
// ---------
/*** $option: true/false; default - false */
$dgrid->allowFiltering(true);
/*** set fileds for filtering */
$f_fields = array(
"Country"=>array("table"=>"tblCountries", "field"=>"Name"),
"Region"=>array("table"=>"tblRegions", "field"=>"Name"),
"Democracy"=>array("table"=>"tblDemocraty", "field"=>"description")
);
$dgrid->setFieldsFiltering($f_fields);
// View Mode Settings:
// ---------
/*** set columns in view mode */
$vm_columns = array(
"Name" =>array("header"=>"Country", "type"=>"label"),
"Region" =>array("header"=>"Region", "type"=>"label"),
"Description" =>array("header"=>"Short Descr.", "type"=>"label"),
"Population" =>array("header"=>"Peoples", "type"=>"label"),
"PictureURL" =>array("header"=>"ImageURL", "type"=>"link", "href"=>"www.yahoo.com", "target"=>"_new"),
"is_democracy" =>array("header"=>"IsDemocracy", "type"=>"label")
);
$dgrid->setColumnsInViewMode($vm_columns);
// Details Mode settings:
// ------------------
/*** set settings for details mode */
$table_name = "tblCountries";
$primary_key = "CountryID";
$dgrid->setTableEdit($table_name, $primary_key);
/*** set columns in details mode */
$e_columns = array(
"RegionID" =>array("header"=>"Region","type"=>"textbox"),
"Name" =>array("header"=>"Country","type"=>"textarea"),
"Description" =>array("header"=>"Short Descr.","type"=>"date"),
"Population" =>array("header"=>"Peoples","type"=>"textbox"),
"PictureURL" =>array("header"=>"ImageURL","type"=>"textbox"),
"is_democracy" =>array("header"=>"IsDemocracy","type"=>"textbox")
);
$dgrid->setColumnsInEditMode($e_columns);
/*** set foreign keys for details mode table */
$f_keys = array(
"RegionID"=>array("table"=>"tblRegions", "field_key"=>"RegionID", "field_name"=>"Name"),
"is_democraty"=>array("table"=>"tblDemocraty ", "field_key"=>"did", "field_name"=>"description")
);
$dgrid->setForeignKeysEdit($f_keys);
// Bind the DataGrid:
// ---------
/*** set debug mode & messaging options */
$debug_mode = false;
$messaging = false;
$dgrid->bind($debug_mode, $messaging);
ob_end_flush();
?>
Thursday, October 05, 2006
New version 1.1.1 of PHP DataGrid
New version 1.1.1 of PHP DataGrid is available for downloading now.
Latest changes:
- fixed bugs in getHeaderName()
- fixed bugs in noDataFound()
- fixed bugs in setColumnsInViewMode()
To download a new version click here.
Latest changes:
- fixed bugs in getHeaderName()
- fixed bugs in noDataFound()
- fixed bugs in setColumnsInViewMode()
To download a new version click here.
Tuesday, October 03, 2006
A few additions
1. Idea
------------------------------
The main idea behind the PHP DataGrid class is the full incapsulation of all needed methods. And also... creation, as fast as possible (few minutes), a good working application.
2. Next version
------------------------------
2nd version comming soon and version 3.xx too... I can't simply upload my non-edited code that I wrote for myself. Sorry, but it should have a better look. It will take a little bit of time :)
3. Good news
------------------------------
Version 2.x.x comes with example of data base.
P.S. Special thanks for your letters with comments. But, please... leave them here.
------------------------------
The main idea behind the PHP DataGrid class is the full incapsulation of all needed methods. And also... creation, as fast as possible (few minutes), a good working application.
2. Next version
------------------------------
2nd version comming soon and version 3.xx too... I can't simply upload my non-edited code that I wrote for myself. Sorry, but it should have a better look. It will take a little bit of time :)
3. Good news
------------------------------
Version 2.x.x comes with example of data base.
P.S. Special thanks for your letters with comments. But, please... leave them here.
Subscribe to:
Posts (Atom)