System Requirements
- PHP 5.2 or later
- Apache or Microsoft IIS web server
- mySQL 4.1 or above
http://phpgrid.com/documentation/ 文档说明地址
System Environment: Web-based
Intended Audience: Non-Technical Users, Web Developers,
Language: Multilingual
Operating System: OS Independent
Programming Language: PHP, jQuery, jqGrid, XHTML, SQL
Database: Any Modern Relational Database (thru ADOdb)
phpGrid version 4 represents a major shift in system architecture. The new version abandends the old programming model which heavily relies on server side scripting, both in rendering and data operations. Much of the datagrid rendering now resides on the client side browser using jQuery and jqGrid. The server side is soley responsible for data CRUD operations. The new version is much more scalable than the previous generation, It also offers more features, such as subgrid and theme roller.
PHP web-based editable datagrid now can be achieved in two lines of code rather than five lines in the previous version. It also use Cascading Style Sheets, or CSS, extensivley for display related tasks, a perfect balance between simplicity and featues.
Please note that in PHP, the method name and parameters are case sensitive.
1
2 3 4 5 6 7 8 |
define
(
'DB_HOSTNAME'
,
'hostname'
)
;
// database host name or TNS name (Oracle only)
define ( 'DB_USERNAME' , 'username' ) ; // database user name define ( 'DB_PASSWORD' , 'password' ) ; // database password define ( 'DB_NAME' , 'sampledb' ) ; // database name define ( 'DB_TYPE' , 'mysql' ) ; // database type define ( 'DB_CHARSET' , 'utf8' ) ; // OPTIONAL. Leave blank to use the default charset define ( 'SERVER_ROOT' , '<URL TO PHPGRID FOLDER>' ) ; // URL to phpGrid folder. Must start with "/" |
IMPORTANT: About SERVER_ROOT
SERVER_ROOT, formerly known as ABS_PATH, represents the absolute URL to the phpGrid library folder on the web server. This value tells your script where to find phpGrid library on the web server.
For instance, if the URL to get to the phpGrid is http://www.yoursite.com/phpGrid, orhttp://localhost/phpGrid, the SERVER_ROOT should be “/phpGrid” (must include the leading forward slash character “/”);
if the URL to phpGrid is http://www.yoursite.com/admin/phpGrid, orhttp://localhost/admin/phpGrid, the SERVER_ROOT should be “/admin/phpGrid“,
and so forth.
Once values in conf.php are set, simply reference phpGrid by adding the following at on top of your PHP code:
1
|
require_once
(
"phpGrid/conf.php"
)
;
|
phpGrid supports wide range of database types. Simply define DB_TYPE parameter value to your own database type. It can be one of the following strings. The default database type for phpGrid is “mysql”. DB_TYPE string is case sensitive.
DB_TYPE | Description |
---|---|
mysql | MySQL (default) |
odbc_mssql | SQL Server |
oci8 | Oracle |
oci8po | Oracle (portable, slightly slower but more reliable) |
postgres | PostGreSql |
access | Microsoft Access |
db2 | DB2 |
odbc | Generic ODBC |
A full list of supported databases and naming convention are available in ADOdb website. Not required but we encourage users to visit ADOdb website. It helps you understand how phpGrid utilizes it under the hood.
When using Oracle database with TNS(Transparent Network Substrate), replace the database host name with the TNS Name in conf.php e.g. define(‘DB_HOSTNAME’,<YOUR ORACLE TNS NAME>);
After successful installation, call the constructor similar to the following:
1
|
$dg
=
new C_DataGrid
(
"SELECT * FROM Orders"
,
"orderNumber"
,
"Orders"
)
;
|
The details of phpGrid constructor is explained below:
__constructor($sql, $sql_key=’id’, $sql_table=”, $db_connection=”)
1
|
$dg
=
new C_DataGrid
(
"SELECT * FROM Orders"
,
"orderNumber"
,
'Orders'
)
;
|
1
2 |
$dg
->
set_query_filter
(
"status='Shipped'"
)
;
$dg -> set_query_filter ( "YEAR(shippedDate) = 2003" ) ; |
* Please note this feature is only available in paid versions.
1
|
$dg
->
enable_edit
(
'FORM'
,
'CRU'
)
;
// Note: delete is disallowed
|
1
|
$dg
->
enable_export
(
'HTML'
)
;
|
1
|
$dg
->
enable_resize
(
true
)
;
|
1
|
$dg
->
display
(
)
:
|
1
|
$dg
->
enable_debug
(
true
)
;
|
1
|
$dg
->
enable_search
(
true
)
;
|
1
|
$dg
->
set_caption
(
''
)
;
// this will hide the caption
|
1
|
$dg
->
set_col_currency
(
"price"
,
"EUR"
,
""
,
","
,
2
,
"0.00"
)
;
|
1
|
$dg
->
set_col_dynalink
(
"productCode"
,
"http://www.example.com/"
,
"orderLineNumber"
,
'&foo=bar'
,
"_top"
)
;
|
1
2 3 4 |
$dg
->
set_col_edittype
(
"officeCode"
,
"select"
,
"1:San Francisco;2:Boston;3:NYC"
,
false
)
;
$dg -> set_col_edittype ( "isActive" , "checkbox" , "1:0" ) ; // bind dropdown menu to a lookup table $dg -> set_col_edittype ( "officeCode" , "select" , "Select officeCode,city from offices" , false ) ; |
1
2 3 |
$dg
->
set_col_format
(
'quantity'
,
'integer'
,
array
(
'thousandsSeparator'
=>
','
,
'defaultValue'
=>
'0'
)
)
;
$dg -> set_col_format ( "emailAddress" , "email" ) ; $dg -> set_col_format ( "weight" , 'number' , array ( "thousandsSeparator" => "," , "decimalSeparator" => "." , "decimalPlaces" => '2' , "defaultValue" => '0.00' ) ) ; |
1
|
$dg
->
set_col_hidden
(
'employeeNumber'
)
;
|
1
|
$dg
->
set_col_img
(
"productImage"
)
|
1
|
$dg
->
set_col_link
(
"productCode"
)
;
|
1
|
$dg
->
set_col_readonly
(
"SSN, lastname, employeeNumber"
)
;
|
1
|
$dg
->
set_col_required
(
"phone, email"
)
;
|
1
|
$dg
->
set_col_title
(
"fname"
,
"First Name"
)
;
|
1
|
$dg
->
set_dimension
(
800
,
600
)
;
|
* Please note this feature is only available in paid versions.
1
2 3 |
$dg
=
new C_DataGrid
(
"SELECT orderId, orderDate, customerId FROM Orders"
,
"orderNumber"
,
"Orders"
)
;
$sdg = new C_DataGrid ( "SELECT lineId,orderId,productCode,price FROM OrderDetails" , "lineId" , "OrderDetails" ) ; $dg -> set_masterdetail ( $sdg , 'orderId' ) ; |
1
|
$dg
->
set_multiselect
(
true
)
;
|
1
|
$dg
->
set_pagesize
(
40
)
;
// display up to 40 rows in a page
|
1
|
$dg
->
set_row_color
(
'yellow'
,
'lightblue'
)
;
|
1
|
$dg
->
set_scroll
(
true
)
;
|
1
|
$dg
->
set_sortname
(
'productName'
)
;
|
1
2 3 |
$dg
=
new C_DataGrid
(
"SELECT orderId, orderDate, customerId FROM Orders"
,
"orderNumber"
,
"Orders"
)
;
$subdg = new C_DataGrid ( "SELECT lineId,orderId,productCode,price FROM OrderDetails" , "lineId" , "OrderDetails" ) ; $dg -> set_subgrid ( $subdg , 'orderId' ) ; |
1
|
$dg
->
set_theme
(
'flick'
)
;
|
1
|
$dg
->
set_col_width
(
"comments"
,
500
)
;
|
* Please note this feature is only available in paid versions.
1
|
$dg
->
set_group_properties
(
'customerNumber'
)
;
|
* Please note this feature is only available in paid versions.
1
2 3 |
$dg
->
set_group_properties
(
'customerNumber'
)
;
$dg -> set_group_summary ( 'amount' , 'sum' ) ; $dg -> set_group_summary ( 'checkNumber' , 'count' ) ; |
1
|
$dg
->
enable_rownumber
(
true
)
;
|
1
|
$dg
->
set_col_align
(
'amount'
,
'right'
)
;
|
1
|
$dg
->
enable_advanced_search
(
true
)
;
|
1
|
$dg
->
set_locale
(
"fr"
)
;
// French locale
|
* Please note this feature is not available in Lite and Basic versions.
$formatoption is the most important parameter which itself is an array contains three elements: condition, value, and css. The elements are described in details as the following:
The first parameter, condition, has the following available value.
eq: Equals
ne: Not Equals
lt: Less than
le: Less than or Equal
gt: Greater than
ge: Greater than or Equal
cn: Contains
nc: Does not Contain
bw: Begins With
bn: Not Begins With
ew: Ends With
en: Not Ends With
The second parameter, value, is the comparing value in the right operand.
css parameter in $formattoptions is an array collection that contains css style element for current cell or row.
1
2 3 4 5 6 7 8 9 10 11 12 13 |
//Format a cell based on the specified condition
$dg -> set_conditional_format ( "orderNumber" , "CELL" , array ( "condition" => "eq" , "value" => "10107" , "css" => array ( "color" => "#ffffff" , "background-color" => "green" ) ) ) ; $dg -> set_conditional_format ( "customerNumber" , "CELL" , array ( "condition" => "eq" , "value" => "141" , "css" => array ( "color" => "red" , "background-color" => "#DCDCDC" ) ) ) ; // Format a row based on the specified condition $dg -> set_conditional_format ( "comments" , "ROW" , array ( "condition" => "cn" , "value" => "request" , "css" => array ( "color" => "white" , "background-color" => "#4297D7" ) ) ) ; |
* Please note this feature is not available in Lite and Basic versions.
1
|
$dg
->
set_databar
(
"percentComplete"
,
"red"
)
;
|
* Please note this feature is not available in Lite and Basic versions.
Note that tstyle and fstyle are CSS styles used as the formatoptions.
1
2 3 4 5 6 7 8 |
.tstyle
{ display : block ; background-image : none ; margin-right : -2px ; margin-left : -2px ; height : 14px ; padding : 5px ; background-color : green ; color : navy ; font-weight : bold } .fstyle { display : block ; background-image : none ; margin-right : -2px ; margin-left : -2px ; height : 14px ; padding : 5px ; background-color : yellow ; color : navy } |
PHP Code
1
2 3 4 5 6 7 |
$dg
->
set_conditional_value
(
"isClosed"
,
"==1"
,
array
(
"TCellValue" => "<img src='SampleImages/checked.gif' />" , "FCellValue" => "<img src='SampleImages/unchecked.gif' />" ) ) ; $dg -> set_conditional_value ( "status" , "=='Complete'" , array ( "TCellStyle" => "tstyle" , "FCellStyle" => "fstyle" ) ) ; |
1
|
$dg
->
enable_autowidth
(
true
)
;
|
1
|
$dg
->
enable_kb_nav
(
true
)
;
|
1
|
$dg
->
set_form_dimension
(
'500px'
)
;
|
* only available in Professional and above.
1
|
$dg
->
set_col_wysiwyg
(
'comments'
)
;
|