Archive › Docs

System Requirements

phpGrid is operating system independent. It works on both Windows and Linux as long as the following components are installed:
  • PHP 5.2 or later
  • Apache or Microsoft IIS web server
  • mySQL 4.1 or above
If you are new to Apache/PHP/mySql, consider using XAMPP, an integrated installation from Apache Friends. It installs Apache, PHP, and MySQL in one batch installation and requires almost no configuration for both Windows and Linux operating systems.
Comments Off

Technical Overview

  • 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.

phpGrid Supports all major web browsers:

databases supported by phpGrid


phpGrid supports all major databases

web browsers supported by phpGrid

Comments ( 0 )

Installation

First and foremost, download the phpGrid from the download page, and then extract the zip file somewhere on your web server.

Before you begin coding using phpGrid, you must specify database information in conf.php. conf.php is our phpGrid configuration file in which we specify database connection parameters and path to the phpGrid. 

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', '/phpGrid_folder'); // URL to phpGrid folder.
 

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, or http://localhost/phpGrid, the SERVER_ROOT should be “/phpGrid“.

if the URL to phpGrid is http://www.yoursite.com/admin/phpGrid, or http://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");

Database Type

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_TYPEDescription
mysqlMySQL (default)
odbc_mssqlSQL Server
oci805Oracle
postgresPostGreSql
accessMicrosoft Access
db2DB2
informixInformix
informix72Alternative Informix Driver
odbcGeneric 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.
new phpGrid now supports local array data source without using a database.

 

Oracle only

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>);

Comments ( 0 )

phpGrid Constructor

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=”)

  • Parameter(s):
    • $sql: SQL SELECT statement. This is the only SQL statement users needs to implement. The SELECT statement must include the primary key as one of the columns if not using the wildcard start(*) in SELECT statement.

      This parameter can also be a local array (version 5.5+). See phpGrid local array data source usage example.
       
    • $sql_key: The name of the primary key of the database table. The default value is “id”.
    • $sql_table: Name of the database table used in the SQL statement. If not defined, the table name is automatically parsed from the SQL statementent.
    • $db_connection: Optional. Since version 4.3, the 4th parameter was introduced and used to overwrite connection parameters in conf.php. It allows datagrid to reference to a difference data source on the fly. See Reference to Multiple Databases example for more information on this parameter. If you have only one database, you can safely ignore this parameter.
  • Description:
    • This is our datagrid object constructor. Use this method to create the phpGrid object. Usually this is the first line in your code.
  • Remark:
    • Do not include WHERE clause in $sql. Instead, use set_query_filter method (version 4.2+) to set filter in your query.
    • If not using the wildcard star(*), the SELECT statement MUST include the primary key as one of the columns.
  • Example:
1
$dg = new C_DataGrid("SELECT * FROM Orders", "orderNumber", 'Orders');
Comments ( 0 )

set_query_filter($WHERE)

  • Parameters:
    • $WHERE: Sql WHERE statement to select data conditionally (DO NOT include WHERE keyword).
  • Description:
    • The query filter is essentially the WHERE clause without the WHERE. The method adds WHERE condition to already existing Sql SELECT statement. Use this method if you have WHERE clause in your SQL statement. You should use the same SQL syntax, such as single quotes around non-numeric values, and even SQL functions.
  • Remark:
    • DO NOT include keyword “WHERE” the filter. phpGrid automatically adds WHERE to the query.
    • Use only SINGLE QUOTE around the filtered value.
  • Example:
1
$dg -> set_query_filter("status='Shipped' AND YEAR(shippedDate) = 2003");
Comments ( 0 )

enable_edit() *

* Please note this feature is only available in paid versions.

  • Parameters:
    • $edit_mode: FORM, or INLINE. The default is FORM.
    • $operations: specify allowed datagrid edit operations.
      • C = Create
      • R = Review
      • U = Update
      • D = Delete
    • By default, all above operations are allowed.
  • Description:
    • When Form edit mode is used, additional icons appear in the data grid footer used for editing. When set to inline mode, the cells in the selected row become editable when the row is clicked. Only a single row can be edited for either mode.
  • Remark:
    • Multiple records can be deleted when multiple select is enabled. See has_multiselect() for more information on this method.
    • For inline edit, the user must press Enter key to save changes
  • Example:
1
$dg -> enable_edit('FORM', 'CRU');  // Everything is allowed but delete
Comments ( 0 )

enable_export()

  • Parameter(s):
    • $type: Export type is either EXCEL or HTML. The default is EXCEL
  • Description:
    • When export is enabled, the export icon appears in the grid footer. The datagrid can be exported in either EXCEL or HTML format. The Excel is exported in native Excel XML format.  More formats will be supported in the future.
  • Example:
1
$dg -> enable_export('HTML');
Comments ( 0 )

enable_resize()

  • Parameter(s):
    • $is_resizable: boolean value indicating whether the phpGrid is resizable.
    • $min_w: minimum resizable width of the datagrid. The default is 350 pixel.
    • $min_h: minimum resizable height of the datagrid. The default is 80 pixel.
  • Description:
    • When $is_resizable is set to true, the small triangle shaped icon is displayed at the right bottom corner of the php data grid. The grid can be resized by simply click and drag the icon using mouse. This is more convenient than setting the width and height by programming.
  • Remark:
    • The method utilizes jQuery UI library. This is currently an experimental feature.
  • Example:
1
$dg -> enable_resize(true);
Comments ( 0 )

display()

  • Parameter(s):
    • $render_content: Optional. True or false. Render content to screen, default value is set to true.
  • Description:
    • This is the method to call to display the datagrid. This is usually the last method to call. It automatically stores the output to output buffer first before rending the data grid.
  • Remark:
    • Unless used together wtih get_display(), it’s not necessary to supply a parameter value.
  • Example:
1
$dg -> display():
Comments ( 0 )

enable_debug()

  • Parameter(s):
    • $debug: boolean value indicating whether to display debug message
  • Description:
    • Enable debug displays phpGrid object as well as the current PHP session information. In addition, XMLHttpRequest, or AJAX, response data is displayed that occurs during CRUD operations. This is helpful debugging information can be used during development.
  • Remark:
    • Make sure this method is not called, or the $debug parameter is set to false, when deployed in production.
  • Example:
1
$dg -> enable_debug(true);
Comments ( 0 )

enable_search()

  • Parameter(s):
    • $can_search: boolean. When set to true, the search icon displays in the footer, and the integrated search is toggled when the icon is clicked.
  • Description:
    • The integrated search provides an intuitive interface for searching data within the datagrid. The user can search one or multiple fields. No additional programming is required. The datagrid is automatically refreshed and repopulated with results returned from the query through AJAX.
  • Remark:
    • The integrated search is toggle off by default. Click on the Search button in the footer to toggle on the integrated search.
  • Example:
1
$dg -> enable_search(true);
Comments ( 0 )

set_caption()

  • Parameter(s):
    • $caption: the text for the grid caption
  • Description:
    • When set, this method displays text above the column header as the datagrid caption. When this method is not called, phpGrid sets the table name as the default caption. For example, the caption will be displayed as “Orders” when the table name is “Orders”.
  • Remark:
    • When caption is set to empty string, e.g. ”, the space used for displaying caption will be hidden, leaves only the column header, grid, and the footer. To display the caption without any text, uses “ ” without the quote.
  • Example:
1
$dg -> set_caption(''); // this will hide the caption
Comments ( 0 )

set_col_currency()

  • Parameter(s):
    • $col_name: column name
    • $prefix: currency prefix. The default is USD symbol, $
    • $suffix: currency suffix. The default is blank.
    • $thousandsSeparator: The character as the thousands separator. The default is the comma character “,”.
    • $decimalSeparator: The character as the decimal separator. The default is the dot character.
    • $decimalPlaces: The number of digital is displayed after the decimal point. The default is two.
    • $defaultValue: The value display when the value return from database is null or empty string. The default is 0.00
  • Description:
    • This is helper method to display currency value. It formats column as currency when displayed. The value is automatically unformatted during CRUD operations.
  • Example:
1
$dg -> set_col_currency("price", "EUR", "", ",", 2, "0.00");
Comments ( 0 )

set_col_dynalink()

  • Parameter(s):
    • $col_name: Name of column to display dynamic URL
    • $baseLinkUrl: The base URL. e.g. “http://www.example.com”
    • $dynaParam: Name of a single data field OR an array of multiple fields. The default is “id” if omitted.
    • $addParam: Optional. Parameters with static value in addition to $dynaParam. They are added to the end of the URL string. e.g. “&foo=bar”
    • $target: Optional. This sets the value of the hyperlink “Target” attribute. The available options are:
      • _new
      • _blank
      • _top
      • _parent
  • Description:
    • This method sets a specific column to display HTML hyperlink URL based on dynamic values. It is different from set_col_link() method where it is simply a static link stored in a data field.
  • Remark:
    • Developers should always check the validity of the dynamic URL constructed when using this method.
  • Example:
1
2
3
4
// a single dynamic field as $dyanParam parameter
$dg -> set_col_dynalink("productCode", "http://www.example.com/", "orderNumber", '&amp;foo=bar', "_top");
// an array of multiple dynamic fields as $dynaParam parameter
$dg -> set_col_dynalink("productCode", "http://www.example.com/", array("orderNumber", "customerNumber", "price"), '&amp;foo=bar', "_top");
Comments ( 0 )

set_col_edittype()

  • Parameter(s):
    • $col_name: Column name
    • $ctrl_type: HTML control type. A list of valid controls are:
      • text
      • textarea
      • select
      • checkbox
      • password
      • button
    • $keyvalue_pair: This parameter is only required when the $ctrl_type is type “select”. It essentially represents list of value key pairs in the dropdown. e.g. “1:San Francisco;2:Boston;3:NYC”. It is ignored if the control type is not “select”.*

      v4.2 Update:
      you can now use values from a database lookup table to bind the dropdown. Simply pass SELECT statement for the $keyvalue_pair when the $ctrl_type is “select”. For example:

          SELECT key, value FROM FOO

    • $multiple: This parameter is only used when control type is “select”. It indicates whether multiple items can be selected in the list of options. The values are passed and stored as a comma delimited string. e.g. “1,2,3″. For single value “select”, this is not required.
  • Description:
    • Set control of a specific column used for grid editing. It displays HTML input tag of different type accordingly e.g. <input type=”text” />, <input type=”textarea” />
    • Remark:
      • Text and textarea are set automatically based on the database access library ADOdb metatype as the default edit control. Users do not need to understand how ADOdb works since phpGrid took care all the plumbing work internally. Isn’t that nice?
    • Example:
    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);
Comments ( 0 )

set_col_format()

  • Parameter(s):
    • $col_name: Datagrid column name
    • $format: The format types are:
      • integer
      • number
      • email
      • link
      • showlink
      • currency
      • date
      • checkbox
      • select
    • $formatoptions: PHP array stores format options of different formatting.
  • Description:
    • Although this method is purely for cosmetic purpose, it is very useful and also practical in many situations when displaying different type of data.
    • Depending on the type of format, it could have different format options. In most cases, users only need to set column formatting for “integer”, “number”, and “mail” using this method. For “currency’, “link”, and “showlink” formats, phpGrid provides a number of helper functions to make formatting simpler and easier. They are
    • The helper functions will be covered later in the documentation.
    • For type “date”, users don’t have to do anything for formatting. The format is automatically set to “date” when the database data field type is date or datetime.
    • In addition, the formats are automatically set as “checkbox” or “select” if the edit type is checkbox or select defined in set_col_edittype().
  • Remark:
    • Though all of the formattings can be done in this method, it is recommended to use helper functions whenever possible. phpGrid ensures the formatting is automated as much as possible. Automation means less coding, and thus less room for error. Simplicity is what phpGrid strives for.
  • Example:
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'));
Comments ( 0 )

set_col_hidden()

  • Parameter(s):
    • $col_name: Column name
    • $edithidden: Boolean value indicating whether the column is editable. The default value is set to true. This only applies when the edit mode is “FORM”.  A hidden column cannot be editable in “INLINE” edit mode.
  • Description:
    • Hide a column in datagrid when displayed
  • Remark:
    • To hide column in both datagrid and form, set the second parameter to false
  • Example:
1
2
3
4
// hide only in grid display
$dg -> set_col_hidden('employeeNumber');
// hide in both gird and edit form
$dg -> set_col_hidden('DOB', false);
 
Tip:
To do the reverse, meaning to have a field appear in grid, but not in the form, use set_col_property set editable to false and hidedlg to true.

1
$dg->set_col_property('COLUMN_NAME', array('editable'=>false,'hidedlg'=>true));
Comments ( 0 )

set_col_img()

  • Parameter(s):
    • $col_name: Colume name
    • $base_Url: Optional. Base URL to image (added in version 5.0)
  • Description:
    • Display as image for a data field in data grid. The optional second parameter is added in version 5.0.  It specifies the base URL/target for all relative URLs to images file.
  • Example:

Assuming the productImag value is “abc.jpg”, the following will render a img tag similar to . The 2nd parameter “/images/” form the base URL to the “abc.jpg”

1
$dg -> set_col_img("productImage", "/images/");
Comments ( 0 )

set_col_link()

  • Parameter(s):
    • $col_name: Column name
    • $target: Hyperlink target attribute. The default is _new
  • Description:
    • Display the text in column as a static hyperlink.
  • Remark:
    • Use this method for displaying static HTML hyperlink. For dynamic links, use set_col_dynalink() method.
  • Example:
1
$dg -> set_col_link("productCode");
Comments ( 0 )

set_col_readonly()

  • Parameter(s):
    • $col_names: Comma delimited one or more column names
  • Description:
    • Set one more more columns as read only field
  • Example:
1
$dg -> set_col_readonly("SSN, lastname, employeeNumber");
Comments ( 0 )

set_col_required()

  • Parameter(s):
    • $col_names: Comma delimited one or more column names
  • Description:
    • Set one more more columns as required field during edit
  • Example:
1
$dg -> set_col_required("phone, email");
Comments ( 0 )

set_col_title()

  • Parameter(s):
    • $col_name: Colume name
    • $new_title: Display title in grid column header
  • Description:
    • Change data grid column header text from the default data field name to more user friendly name
  • Remark:
    • The default column header text is the database table data field name
  • Example:
1
$dg -> set_col_title("fname", "First Name");
Comments ( 0 )

set_dimension()

  • Parameter(s):
    • $width: Datagrid width
    • $height: Datagrid height. The default is 100% which expanses grid vertically to the entire browser height
    •  $shrinkToFit: true or false. If set to false, horizontal bar will appear when the total width of grid is wider than the dimesion width. The default is true.
  • Description:
    • Set the overall height and width of phpGrid
  • Remark:
    • It is recommended to set $shrinkToFit to false when there are a large number of columns to display.
  • Example:
1
$dg -> set_dimension(800, 600);
Comments ( 0 )

set_jq_datatype()

  • Parameter(s):
    • $datatype: Internal data source type. It can be either “json” or “xml“. The default is “json“.
  • Description:
    • Manually sets data type used by jqGrid when displaying data grid.
  • Remark:
    • In most cases, you do not need to call this method.
Comments ( 0 )

set_jq_editurl()

  • Parameter(s):
    • $url: URL
  • Description:
    • Manually set URL used for editing. The default URL is edit.php. phpGrid takes care all of data insert, delete, and update in edit.php. No coding is required.
  • Remark:
    • Only use this method when the users need to mannually handle data update using their own routin.
    • In most cases, you do not need to call this method.
Comments ( 0 )

set_jq_gridName()

  • Parameter(s):
    • $grid_name: Unique name of the datagrid used internally by phpGrid
  • Description:
    • Manually set the unqiue name of the datagrid. By default, the name is the database table name associated with the grid.
  • Remark:
    • In most cases, you do not need to call this method.
Comments ( 0 )

set_masterdetail() *

* Please note this feature is only available in paid versions.

  • Parameter(s):
    • $obj_grid: phpGrid object as the detail datagrid
    • $fkey: Foreign key to the detail table.
  • Description:
    • This method sets the master detail, or the parent child, relationship between datagrids.
    • The phpGrid went the extra mile to make creating the master detail datagrid a simple task for developers. The primary key value of master datagrid is auomatically retrieved when user selects a row and used as the value to the foreign key in the detail grid. The detail grid renders dynamically based on the row selected in parent grid.
  • Remark:
    • The detail grid is a regular phpGrid object and can have the same methods like any other phpGrid, such as description title, sort, and update etc. A master detail can have one or more detail datagrid. The foreign key, or $fkey, does NOT necessarily have to have the same name as the master table primary key, as long as the same name exists in both master and detail tables.
    • When foreign keys don’t have the same name, you should use SQL alias.
    • Master grid prefills a detail grid with the value of the foreign key during data entry add operation. Version 4.5.5 and above only.
  • Example:
1
2
3
4
// orderId exists in both master table(Orders) and detail table(OrderDetails)
$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');

When foreign keys don’t have the same name, you can use SQL alias.

1
2
3
4
// productId is SQL alias to productNo in master table(ProductParts), then used as foreign key to link to detail table(Products).
$dg = new C_DataGrid("SELECT partNo, partName, productNo AS productId FROM ProductParts", "partNo", "ProductParts");
$sdg = new C_DataGrid("SELECT productId, productName, productDescription FROM Products", "productId", "Products");
$dg -> set_masterdetail($sdg, 'productId');
Comments ( 0 )

set_multiselect()

  • Parameter(s):
    • $multiselect:  Boolean value indicates whether the multiselect is allowed
  • Description:
    • When parameter $multiselect is set to true, a checkbox is shown to the left of each row. It is currently only used for enabling deleting multiple records. More functions will be added to this feature in the future.
  • Example:
1
$dg -> set_multiselect(true);
Comments ( 0 )

set_pagesize()

  • Parameter(s):
    • $pagesize: An integer value indicates number of results displaying in a page in the datagrid
  • Description:
    • This method changes the default pagination of the datagrid. The default is 20.
  • Remark:
  • Example:
1
$dg -> set_pagesize(40);  // display up to 40 rows in a page
Comments ( 0 )

set_row_color()

  • Parameter(s):
    • $hover_color: Background color when mouse is over a row
    • $highlight_color: Background color when a row is clicked on
    • $alt_color: Alternating row color
  • Descript:
    • This method is pure cosmetic. When modified, it overwrites color of jQuery UI properties:
      • ui-state-hover,
      • ui-state-highlight
      • ui-priority-secondary
  • Example:
1
$dg -> set_row_color('yellow', 'lightblue', 'lightgray');
Comments ( 0 )

set_scroll()

  • Parameter(s):
    • $scroll: Boolean value indicates wheter
    • $height: phpGrid height
  • Description:
    • Use vertical scroll to load data. The datagrid will not load everything at once and will hold all the items from the start through to the latest point ever visited. This prevents memory leaks from happening.
  • Remark:
    • Pagination is disabled when scroll is set to true.
    • The default height is 400 when scroll is true and should never be ’100%’.
  • Example:
1
$dg -> set_scroll(true);
Comments ( 0 )

set_sortname()

  • Parameter(s):
    • $col_name: Column name to sort
    • $sort_order: ’ASC’ or ‘DESC’. Default value is ‘ASC’  (version 4.4+)
  • Description:
    • Set column sort by and sort order when datagrid is initially loaded.
  • Example:
1
$dg -> set_sortname('productName', 'DESC');
Comments ( 0 )

set_subgrid()

  • Parameter(s):
    • $obj_grid: phpGrid object as subgrid
    • $s_fkey: subgrid foreign key.
    • $m_fkey: Optional. Master foreign key. (ver 4.5+).
  • Description:
    • The method displays inline and read-only detail grid rather than in separate datagrid table. It is similar to set_masterdetail() except it can takes an additional parameter as the foreign key from master grid. When ignored, phpGrid assumes that m_fkey has the same value as the s_fkey.
  • Remark:
    • Edit is currently not supported in subgrid.
    • Nested subgrid is currently not supported.
    • The 3rd parameter is only available to version 4.5 and above.
    • When the subgrid is the same table(self-reference, in database term) as the master grid, subgrid must use an different alias as table name in the select statement.
  • Example:
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');
Comments ( 0 )

set_theme()

  • Parameter(s):
    • $theme_name: Theme name
  • Description:
    • This is the phpGrid “Theme Roller”. phpGrid bundles the following themes from jQuery UI:
      • ‘dot-luv’
      • ‘excite-bike’
      • ‘flick’
      • ‘overcast’
      • ‘pepper-grinder’
      • ‘redmond’
      • ‘smoothness’
      • ‘start’
      • ‘ui-darkness’
      • ‘ui-lightness’
    • The default theme is ‘start‘.
  • Example:
1
$dg -> set_theme('flick');
Comments ( 0 )

set_col_width()

  • Parameters:
    • $col_name: column name
    • $width: width
  • Description:
    • Specify column width in pixel. The width should be an integer value.
  • Example:
1
$dg -> set_col_width("comments", 500);
Comments ( 0 )

set_group_properties() *

* Please note this feature is only available in paid versions.

  • Parameters:
    • $column_name: column name for grouping
    • $groupCollapsed: boolean value indicating whether to expand or collapse grouping when displayed.  The default is false.
    • $showSummaryOnHide: boolean value indicating whether to display group summary when grouping is collapsed. The default is true.
  • Description:
    • Group grid values simply by specifying a column name.
  • Remark:
    • Single level grouping is currently supported.
    • When grouping is enabled, the followings methods are disabled:
      • set_scroll();
      • enable_rownumbers();
      • set_subgrid();
  • Example:
1
$dg -> set_group_properties('customerNumber');
Comments ( 0 )

set_group_summary() *

* Please note this feature is only available in paid versions.

  • Parameters:
    • $column_name: column name for grouping
    • $summaryType: summary type. It can be one of the types below
      • sum
      • count
      • avg
      • min
      • max
  • Description:
    • Display group summary of a specific summary type, such as sum or max, in the group summary footer.
  • Remark:
  • Example:
1
2
3
$dg -> set_group_properties('customerNumber');
$dg -> set_group_summary('amount','sum');
$dg -> set_group_summary('checkNumber','count');
Comments ( 0 )

enable_rownumbers()

  • Parameters:
    • $has_rownumbers: boolean value indicating whether row number is displayed.
  • Description:
    • Display row number before each row.
  • Example:
1
$dg -> enable_rownumbers(true);
Comments ( 0 )

set_col_align()

  • Parameters:
    • $col_name: column name
    • $align: alignment direction: “left”, “center”, or “right”.
  • Description:
    • Horizontal alignment of text in a column. The default alignment is left.
  • Example:
1
$dg -> set_col_align('amount', 'right');
Comments ( 0 )

enable_advanced_search()

  • Parameters:
    • $has_adsearch: boolean value. Set true to enable advanced search
  • Description:
    • Advanced search is different from the integrated search (see enable_search()). It can apply mulitple conditionals to a single field during advanced search. It is super flexible and easy to use.
  • Example:
1
$dg -> enable_advanced_search(true);

Comments ( 0 )

set_locale()

  • Parameters:
    • $locale: language locale. List of values are: bg, cat, cn, cs, de, dk, el, en, fa, fi, fr, he, is, it, ja, nl, no, pl, pt, ro, ru, sp, sv, tr, ua.
  • Description:
    • If you are using phpGrid in a language rather English, you may want the datagrid to display appropriate system text used by phpGrid such as “Submit”, “Next”, “Page”, “Find” etc. The language locale files are located in js\src\i18n directory.
  • Example:
1
$dg -> set_locale("fr"); // French locale
Comments ( 0 )

set_conditional_format() *

* Please note this feature is not available in Lite and Basic versions.

  • Parameters:
    • $col_name: column name
    • $type: CELL or ROW
    • $formatoptions: array that stores condition and css style options
  • Description:
    • Format a cell based on the specified condition. CELL formats the a single cell. ROW formats the entire row.
       

      $formatoption is the most important parameter which itself is an array contains three elements:

      • condition,
      • value,
      • 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.

  • Example:
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")));
Comments ( 0 )

set_databar() *

* Please note this feature is not available in Lite and Basic versions.

  • Parameters:
    • $col_name: Name of column to display data bar. It should be numeric type
    • $color: Data bar color
  • Description:
    • Creates a data bar with gradient effect on a specified column. For complex data visualization, PHP Chart is highly recommended.
  • Remark:
    • For complex data visualization, we recommend phpGrid sister product, PHP Chart, a highly customizable PHP charting solution.
  • Example:
1
$dg -> set_databar("percentComplete","red");
Comments ( 0 )

set_conditional_value() *

* Please note this feature is not available in Lite and Basic versions.

  • Parameters:
    • $col_name: Name of the column. Its value is used as the left operand for comparison.
    • $condition: comparison condition that compares given left and rigth hand operand with comparison operator . e.g. ” > 10 “; ” = ‘abc’”; ” != true ” etc.
    • $formatoptions:  an array stores CSS style format options. The value can be text, HTML, or even CSS class. See example.
      • TCellValue: value to display when condition is True
      • FCellValue: value to display when condition is False
  • Description:
    • It formats and displays value in a cell when specified condition is met. You can think it as a simplified version to set_conditional_format() method.
  • Remark:
    • The condition is not “stackable” for a single column. In other words, only one condition can be applied to any giving column.
  • Example:

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" alt="" />",
"FCellValue"=>"<img src="SampleImages/unchecked.gif" alt="" />"));

$dg->set_conditional_value("status", "=='Complete'", array(
"TCellStyle"=>"tstyle",
"FCellStyle"=>"fstyle"));
Comments ( 0 )

enable_autowidth()

  • Parameters:
    • $autowidth: true or false
  • Description:
    • Use this method to set datagrid width as the same as the current page width.
  • Example:
1
$dg->enable_autowidth(true);
Comments ( 0 )

get_display()

  • Parameters:
    • $add_script_includeonce: true or false. Whether or not to include script header.
  • Description:
    • It returns the grid body with options to include script header. It is useful for MVC framework integration such as Joomla! and Drupal.
  • Remark:
    • The get_display() function should be called AFTER display() is called so that the grid body and header is saved to an internal output buffer that can be later retrieved by get_display().

Example:

1
2
3
4
5
6
7
8
9
$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");
$dg -> display(false);  // do not render display
$grid = $dg -> get_display(false);  // do not include required javascript libraries until later with with display_script_includeonce method.

// other page content goes here
/* ........................... */

$dg -> display_script_includeonce();
echo $grid;
Comments ( 0 )

enable_kb_nav() – beta

  • Parameters:
    • $is_enabled: true or false
  • Description:
    • Enable navigation by keyboard using up and down arrow keys.
  • Remark:
    • This is a beta feature currently. Not recommended using it in production.
  • Example:
1
$dg->enable_kb_nav(true);
Comments ( 0 )

set_form_dimension()

  • Parameters:
    • $f_width: form width. The default value is ’400px’
    • $f_height: form height. The default is -1 so it is automatically adjusted to number of rows.
  • Description:
    • Set edit FORM width and height during edit.
  • Remark:
    • The default $f_height value is -1 (negative one) so it is automatically adjusted to number of rows.
  • Example:
1
$dg->set_form_dimension('500px');
Comments ( 0 )

setCallBack

  • Parameters:
    • $callback_str: callback string
  • Description:
    • Used for pass setting between 3rd party system and phpGrid using AJAX callback. Read the comments in file callbackstr.php for usage
Comments ( 0 )

set_col_wysiwyg()

* only available in Professional and above.

  • Parameters:
    • $col_name: column name
  • Description:
    • Turns simple text field into word processor by replacing textarea with rich text editor. Should only be used for text fields that allows large amount of text such as notes and comment fields.
  • Remark:
    • The field must be a text data type. If not, use set_col_edittype and set edit type to “textarea” first.
  • Example:
1
2
// comments is text data type
$dg->set_col_wysiwyg('comments');
1
2
3
// news is not a text data type
$dg->set_col_edittype('news', 'textarea');
$dg->set_col_wysiwyg('news');
Comments ( 0 )

set_col_default()

  • Parameters:
    • $col_name: column name
    • $default: column default value
  • Description:
    • Set column default value This option is only valid for Form Editing when adding a new record. User can override this entry.
  • Example:
1
$dg -> set_col_default('direction', 'top');
Comments ( 0 )

set_col_fileupload() *

* Please note this feature is currently only available for Enterprise and Universal licenses.

  • Parameters:
    • $col_name: column name that stores file name
    • $base_url: base URL to the files
    • $physical_path: specify physical path to the folder where the files are uploaded. When PHP is installed as Apache module, this parameter is optional.
  • Description:
    •  The file upload is seamlessly integrated with the edit form using Ajax, no page refresh ever occurred. Files can be uploaded and deleted right within the form.
  • Remark:
    • A single file upload per datagrid is allowed.
    • FORM edit mode only
    • File system only with valid upload_tmp_dir value in php.ini
    • File name column should allow NULL value
    • $physical_path is automatically obtained if PHP running in Apache module, or MUST be provided as fallback
  • Example:
1
2
3
4
$dg -> set_col_fileupload("fileToUpload", "/phpGridx/FileUploadFolder/", "c:\\xampp\www\\phpGridx\\FileUploadFolder\\");

// if PHP is installed as Apache module, the 3rd parameter, $physical_path, can be ignored
$dg -> set_col_fileupload("fileToUpload", "/phpGridx/FileUploadFolder/");
Comments ( 0 )

set_col_date()

  • Parameters:
    • $col_name: column name
    • $srcformat: source date format, eg. “Y-m-d”
    • $newformat: new date form to be displayed, eg. “n/j/Y”
    • $datepicker_format: datepicker format, eg. “m/dd/yy”
  • Description:
  • Remark:
    • In most cases, you don’t need to call this method because phpGrid automatically formats the data with corresponding data type including date.
    • Only use this method in order to display date format that is different from default date format.
    • To display time only, please use set_col_property instead.
  • Example:
1
2
3
4
// srcFormat: MySql date format is "Y-m-d"
// newFormat: Display date format is "n/j/Y"
// datepicker: Datepicker date format is "yy-mm-dd"
$dg -> set_col_date("orderDate", "Y-m-d", "n/j/Y", "yy-mm-dd");
Comments ( 0 )

set_col_edit_dimension

  • Parameters:
    • $col_name: column name
    • $size/$cols: If the column is a text box, it’s the size that represents number of characters. If the column is a textarea, it’s the value for cols attribute in textarea.
    • $rows: Optional. Number of rows in a textarea
  • Description:
    •  Set input text box size or textarea cols and rows values in edit form.
  • Remark:
  • Example:
1
2
3
4
5
// status is a text fields, 40 indicates the text field is 40 characters long.
$dg -> set_col_edit_dimension("status", 40);

// comments, a text data type, is rendered as textarea with cols set to 50, rows set to 10
$dg -> set_col_edit_dimension("comments", 50, 10);
Comments ( 0 )

set_col_property()

  • Parameters:
  • Description:
    •  This method allows you to directly manipulate column properties.  Since column properties are an array, you can directly change the properties. This is more “closer to the metal” for users who are already familiar with jqGrid colMdel API.
  • Remark:
    • This is an advanced method. In most cases, you don’t need to call this method.  It does not replace existing helper functions such as set_col_date, set_col_currency, etc. We suggest you use those helper functions if you are new to phpGrid.
  • Example:
1
2
3
4
5
6
7
$dg -> set_col_property("orderNumber", array("name"=>"Order Number", "width"=>40));
$dg -> set_col_property("orderDate", 
                             array("formatter"=>"date",
                                   "formatoptions"=>array("srcformat"=>"Y-m-d","newformat"=>"m/d/Y")));  // display different time format
$dg -> set_col_property("shippedDate",
            array("formatter"=>"date",
                "formatoptions"=>array("srcformat"=>"ISO8601Short","newformat"=>"g:i A")));  // display time only
Comments ( 0 )

add_event()

  • Parameter(s):
    • $event_name: Event name from one of the following available events
      • jqGridResizeStart
      • jqGridResizeStop
      • jqGridAfterInsertRow
      • jqGridGridComplete
      • jqGridAfterGridComplete
      • jqGridBeforeRequest
      • jqGridLoadComplete
      • jqGridAfterLoadComplete
      • jqGridSortCol
      • jqGridSelectAll
      • jqGridBeforeSelectRow
      • jqGridCellSelect
      • jqGridDblClickRow
      • jqGridRightClickRow
      • jqGridHeaderClick
      • jqGridSelectRow
      • jqGridShowHideCol
      • jqGridRemapColumns
      • jqGridKeyLeft
      • jqGridKeyRight
      • jqGridKeyEnter
      • jqGridKeySpace
      • jqGridToolbarBeforeSearch
      • reloadGrid
      • jqGridToolbarAfterSearch
      • jqGridToolbarBeforeClear
      • jqGridToolbarAfterClear
      • jqGridFilterBeforeShow
      • jqGridFilterAfterShow
      • jqGridFilterInitialize
      • jqGridFilterSearch
      • jqGridFilterReset
      • jqGridAddEditBeforeCheckValues
      • jqGridAddEditClickSubmit
      • jqGridAddEditBeforeSubmit
      • jqGridAddEditErrorTextFormat
      • jqGridAddEditAfterSubmit
      • jqGridAddEditAfterComplete
      • jqGridAddEditBeforeInitData
      • jqGridAddEditBeforeShowForm
      • jqGridAddEditAfterShowForm
      • jqGridAddEditInitializeForm
      • jqGridAddEditClickPgButtons
      • jqGridAddEditAfterClickPgButtons
      • jqGridInlineEditRow
      • jqGridInlineAfterSaveRow
      • jqGridInlineSuccessSaveRow
      • jqGridInlineErrorSaveRow
      • jqGridInlineAfterRestoreRow
      • jqGridBeforeEditCell
      • jqGridAfterEditCell
      • jqGridSelectCell
      • jqGridBeforeSaveCell
      • jqGridBeforeSubmitCell
      • jqGridAfterSubmitCell
      • jqGridAfterSaveCell
      • jqGridErrorCell
      • jqGridAfterRestoreCell
      • jqGridSubGridBeforeExpand
      • jqGridSubGridRowExpanded
      • jqGridSubGridRowColapsed
      • jqGridGroupingClickGroup
      • jqGridImportComplete
    • $js_event_handler: JavaScript event handler to the specified event
  • Description:
  • Remark:
    • This is an advanced method.  The event handler is JavaScript.
  • Example:
Comments ( 0 )

display_script_includeonce()

  • Parameter(s):
    • None
  • Description:
    • Includes required Javascript libraries before displaying our grids.
  • Remark:
    • Developers don’t need to call this method to include required Javascript libraries (jqGrid, jwysiwyg, ajaxfilupload etc.) because the phpGrid includes those Javascript automatically for you. This method is only used in get_display() in a MVC framework.
Comments ( 0 )

add_column()

  • Parameter(s):
    • $col_name: Name of the calculated/virtual column. It cannot have space and must NOT be one of the existing database column names.
    • $property: Column properties. See set_col_property() for available column properties usage.
    • $title: Optional. Title for this virtual column. If omitted, it’s the same as the column name $col_name.
  • Description:
    • Append virtual column, AKA calculated column, to the end of an existing datagrid with this method.
  • Remark:
    • The $col_name cannot contain space and must begin with a letter
    • Use “formatter” column property to hook up Javascript function, e.g. below, $col_formatter is the Javascript to display value in virtual column.
    • The virtual column always adds to the end of the grid in the order of virtual column is created.
    • Text must be surrounded with SINGLE quote.
    • Virtual column is not sortable.
  • Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$col_formatter = <<<COLFORMATTER
function(cellvalue, options, rowObject){
var n1 = parseInt(rowObject[0],10),    // get value from column #1
n2 = parseInt(rowObject[6],10);        // get value from column #7
return n1+n2;    
}
COLFORMATTER
;

$dg -> add_column(
        'total',
        array('name'=>'total',
            'index'=>'total',
            'width'=>'360',
            'align'=>'right',
            'formatter'=>$col_formatter),
        'Total (Virtual)');
Comments ( 0 )

set_col_customrule()

  • Parameters:
    • $col_name: column name
    • $custom rule: Javascript function to validate data
  • Description:
    • Create custom javascript validation for column value during edit. phpGrid has automatic default validation based on database data type. This method comes in handy when additional data validation is required such as value range, data dependency etc.
  • Example:
1
$dg->set_col_customrule('quantityInStock', 'price_validation1');  // price_validation is a javascript function defined somewhere else
Comments ( 0 )

set_col_frozen()

  • Parameter(s):
    • $col_name: Column name
  • Description:
    • Similar to Excel column freeze, phpGrid can now freeze column(s)
  • Remark:
    • Note that the frozen columns should be from left to right, one after other.
    • In inline edit, the frozen columns are not editable.
    • Columns are not draggable if any column is frozen
  • Example:
1
2
// freeze both customer_id and customer_name columns
$dg -> set_col_frozen("customer_id")->set_col_frozen("customer_name"):
Comments ( 0 )

set_grid_method()

  • Parameter(s):
    • $method_name: method name
    • $options: method options. It must be an array. Different method has different options.
  • Description:
  • Remark:
    • Only available in 5.5.5 and higher.
    • Only use this method to call jqGrid methods that can act on the grid as a whole. It’s NOT possible to manipulate the grid on a row or cell level using set_grid_method because the generated javascript code is appended to the end of the script before closing bracket.
  • Example:
1
2
3
4
5
6
7
// create group header using this method
$dg->set_grid_method('setGroupHeaders', array(
                                array('useColSpanStyle'=>true),
                                'groupHeaders'=>array(
                                        array('startColumnName'=>'customerNumber',
                                              'numberOfColumns'=>2,
                                              'titleText'=>'Numbers Header') )));
Comments ( 0 )
Top