Examples Archives | phpGrid - PHP Datagrid https://phpgrid.com/category/example/ Create PHP grids in minutes, not hours. Fri, 06 Dec 2024 02:55:23 +0000 en-US hourly 1 CodeProjecthttps://wordpress.org/?v=7.0.3 129966043 Introduction https://phpgrid.com/example/introduction/ Sun, 04 Jul 2010 19:37:24 +0000 http://64.38.236.7/?p=476 Welcome to phpGrid! The most beloved datagrid for PHP developers. If you are new to phpGrid, we recommend that you go through the examples in the sequence provided for each section. Before you begin, make sure that you have installed and configured phpGrid properly. phpGrid utilizes jQuery extensively, the popular cross-browser Javascript framework. The current […]

The post Introduction appeared first on phpGrid - PHP Datagrid.

]]>
phpGrid Logo

Welcome to phpGrid! The most beloved datagrid for PHP developers. If you are new to phpGrid, we recommend that you go through the examples in the sequence provided for each section.

Before you begin, make sure that you have installed and configured phpGrid properly. phpGrid utilizes jQuery extensively, the popular cross-browser Javascript framework. The current phpGrid supports jQuery version 3. If you are already using jQuery but a different version, considering removing the existing jQuery to avoid version conflicts. If you have questions regarding this, please send us an email.

Please note, certain features, such as update, delete, and add new are disabled in online demo for security reason. In addition to the examples, major phpGrid features can be seen in Screenshots page.

The post Introduction appeared first on phpGrid - PHP Datagrid.

]]>
476
A Basic PHP Grid Example https://phpgrid.com/example/example-1-a-basic-php-datagrid-2/ Mon, 05 Jul 2010 19:40:36 +0000 http://64.38.236.7/?p=481 A basic PHP grid requires only as little as TWO lines of code. First of all, always create a phpGrid object in the first line; then call its methods to define properties, and lastly always call display() to render to screen. parameter 1: SQL query parameter 2: SQL primary key parameter 3: SQL table name […]

The post A Basic PHP Grid Example appeared first on phpGrid - PHP Datagrid.

]]>
A basic PHP grid requires only as little as TWO lines of code. First of all, always create a phpGrid object in the first line; then call its methods to define properties, and lastly always call display() to render to screen.

  • parameter 1: SQL query
  • parameter 2: SQL primary key
  • parameter 3: SQL table name

 
PHGRID CONSTRUCT

The third parameter is ALWAYS equals to the database table name (illustrated above). In addition, do not include “WHERE” clause in $sql. Instead use set_query_filter() to set query filter.
X

Complete code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
use phpCtrl\C_DataGrid;

require_once("../conf.php");      
?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>A Basic PHP Datagrid</title>
</head>
<body>
<?php
$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");
$dg -> display();
?>
</body>
</html>

See Live Demo!

How to obtain demo database ‘sampledb’

The demo database is available inside the folder “examples\SampleDB“. The file name suggests its associated database type. The following demo databases are included for your convenience: MySQL, MS SQL Server, DB2, SQLite, MS Access, Oracle, Postgres.

Please note in some databases, such as Firebird, MS Access, the fields name are case-sensitive. Make sure the name used in the code matches the case when you are using those type of databases.

Database naming standards

It’s generally not recommended to have hyphen or space character in naming database tables, or you must add surrounding quotes, or back ticks to the table names or columns that have those characters in SQL query. Underscore character, on the other hand, is generally accepted for naming convention.

1
2
SELECT * FROM `my-table` -- requires ` around table name
SELECT * FROM my_table  -- does not require surrounding quotes.

Common issue:

1
"Fatal error: Class "C_DataGrid" not found in ..."

phpGrid namespace on KB:
https://phpgrid.uservoice.com/knowledgebase/articles/896817-laravel-fatal-error-class-c-datagrid-not-found

The post A Basic PHP Grid Example appeared first on phpGrid - PHP Datagrid.

]]>
481
Descriptive Column Header https://phpgrid.com/example/example-descriptive-column-headers/ Thu, 16 Sep 2010 00:09:29 +0000 http://64.38.236.7/?p=492 By default phpGrid pulls out the data field name defined in database as the header for each column. You can simply change the title using method set_col_title(). 12345678910111213// Always include namespace and conf.php on TOP of the script. use phpCtrl\C_DataGrid; require_once("/file/path/to/conf.php");   $dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders"); // change column titles $dg […]

The post Descriptive Column Header appeared first on phpGrid - PHP Datagrid.

]]>
By default phpGrid pulls out the data field name defined in database as the header for each column. You can simply change the title using method set_col_title().

1
2
3
4
5
6
7
8
9
10
11
12
13
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");

// change column titles
$dg -> set_col_title("orderNumber", "Order No.");
$dg -> set_col_title("orderDate", "Order Date");
$dg -> set_col_title("shippedDate", "Shipped Date");
$dg -> set_col_title("customerNumber", "Customer No.");

$dg -> display();

See Live Example!

The post Descriptive Column Header appeared first on phpGrid - PHP Datagrid.

]]>
492
Hide Column https://phpgrid.com/example/hide-column/ Thu, 16 Sep 2010 00:13:39 +0000 http://64.38.236.7/?p=498 For columns need not to be shown, such as primary key, use method set_col_hidden() to hide those columns. To hide column in both datagrid and form, set the second parameter to false. This is useful to hide the auto increment primary key field from edit form.   12345678910111213141516// Always include namespace and conf.php on TOP […]

The post Hide Column appeared first on phpGrid - PHP Datagrid.

]]>
For columns need not to be shown, such as primary key, use method set_col_hidden() to hide those columns. To hide column in both datagrid and form, set the second parameter to false. This is useful to hide the auto increment primary key field from edit form.

Important: The data are still sent to web browser but hidden using CSS display:none. For sensitive data such as passwords and SSN etc, do not use this method, instead do not include those fields in your SQL at all.
X
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");

// change column titles
$dg -> set_col_title("orderNumber", "Order No.");
$dg -> set_col_title("orderDate", "Order Date");
$dg -> set_col_title("shippedDate", "Shipped Date");
$dg -> set_col_title("customerNumber", "Customer No.");
 
// hide a column
$dg -> set_col_hidden("requiredDate");
 
$dg -> display();

To display in the grid but hide when edit, you can use the following:

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

See Live Example!

The post Hide Column appeared first on phpGrid - PHP Datagrid.

]]>
498
Datagrid Caption https://phpgrid.com/example/datagrid-caption/ Thu, 16 Sep 2010 00:16:04 +0000 http://64.38.236.7/?p=501 By default, phpGrid displays table name as the caption. You can change the datagrid caption using set_caption(). You can also hide the caption by using an empty string “” as the caption. 12345678910111213141516171819// Always include namespace and conf.php on TOP of the script. use phpCtrl\C_DataGrid; require_once("/file/path/to/conf.php");   $dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", […]

The post Datagrid Caption appeared first on phpGrid - PHP Datagrid.

]]>
By default, phpGrid displays table name as the caption. You can change the datagrid caption using set_caption(). You can also hide the caption by using an empty string “” as the caption.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");

// change column titles
$dg->set_col_title("orderNumber", "Order No.");
$dg->set_col_title("orderDate", "Order Date");
$dg->set_col_title("shippedDate", "Shipped Date");
$dg->set_col_title("customerNumber", "Customer No.");
 
// hide a column
$dg -> set_col_hidden("requiredDate");

// change default caption
$dg -> set_caption("Orders List");
 
$dg -> display();

See Live Example!

The post Datagrid Caption appeared first on phpGrid - PHP Datagrid.

]]>
501
Export Data to Excel, PDF, CSV, and HTML https://phpgrid.com/example/export-datagrid-to-excel-or-html/ Thu, 16 Sep 2010 00:18:41 +0000 http://64.38.236.7/?p=503    phpGrid currently supports export in native Excel format, CSV, PDF, and HTML format. When the export feature is enabled, phpGrid displays an export icon in the footer. Users can export data to Excel in php or any one of the supported file formats Also see enable_export().   If you want to enable users to […]

The post Export Data to Excel, PDF, CSV, and HTML appeared first on phpGrid - PHP Datagrid.

]]>
export_icons

  

phpGrid currently supports export in native Excel format, CSV, PDF, and HTML format. When the export feature is enabled, phpGrid displays an export icon in the footer. Users can export data to Excel in php or any one of the supported file formats Also see enable_export().

 
If you want to enable users to export data from the PHP grids, you should enable this feature. By default, users can export to Microsoft Office Excel, PDF, HTML, or CSV any list of data that appears in a grid. Export to Excel produces native Microsoft Excel .xls file format.
 
Native Excel .xls format is now supported in version 6.7. Previously Excel export is in OpenOffice XML .xml format.
X
Users can export data to Excel in php or any one of the supported file formats by clicking the Export button that appears in the footer. Users can only export data appears in the datagrid. All hidden columns made with set_col_hidden() are not included in the export. It is not recommended to enable export feature when the datagrid contains data such as social security numbers or passwords.
 
When users click Export button, the phpGrid will generate the export file by using data from the database table in Ajax. Data that does not appear on the screen is not exported. If search filter is used, only the filtered results are exported.
 

When the datagrid contains fields that reference to others database tables through lookups, the text will be used in the export rather than the id fields. Please check out the “select” control type in set_col_edittype function.

 
PDF and CSV formats are now supported (Available to Premium Edition) !
 

grid-export

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");
// change column titles
$dg->set_col_title("orderNumber", "Order No.");
$dg->set_col_title("orderDate", "Order Date");
$dg->set_col_title("shippedDate", "Shipped Date");
$dg->set_col_title("customerNumber", "Customer No.");
// hide a column
$dg->set_col_hidden("requiredDate");
// change default caption
$dg->set_caption("Orders List");
// EXCEL export
$dg->enable_export('PDF');
$dg->display();

$dg2 = new C_DataGrid("select * from customers", "customerNumber", "Customers");
// PDF export
$dg2->enable_export('EXCEL');
$dg2->display();

See Live Demo!

The post Export Data to Excel, PDF, CSV, and HTML appeared first on phpGrid - PHP Datagrid.

]]>
503
Integrated Search https://phpgrid.com/example/integrated-search/ Thu, 16 Sep 2010 00:20:38 +0000 http://64.38.236.7/?p=505 phpGrid includes integrated search. By default, this feature is not enabled. To enable search use enable_search() method with parameter set to true. Once enabled, the integrated search can be toggled with the search button on the footer.     Notice the “status” is automatically rendered as a drop-down in the integrated search(v5.5+). Talking about making […]

The post Integrated Search appeared first on phpGrid - PHP Datagrid.

]]>
phpGrid includes integrated search. By default, this feature is not enabled. To enable search use enable_search() method with parameter set to true. Once enabled, the integrated search can be toggled with the search button on the footer.

 

Integrated Search

 

Notice the “status” is automatically rendered as a drop-down in the integrated search(v5.5+). Talking about making your life easy? :)

To always display the search toolbar, please see Always display integrated search toolbar on KB.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

$dg = new C_DataGrid("SELECT * FROM Orders", "orderNumber", "Orders");

// change column titles
$dg->set_col_title("orderNumber", "Order No.");
$dg->set_col_title("orderDate", "Order Date");
$dg->set_col_title("shippedDate", "Shipped Date");
$dg->set_col_title("customerNumber", "Customer No.");
 
// hide a column
$dg -> set_col_hidden("requiredDate");

// change default caption
$dg -> set_captin("Orders List");

// set export type and edit select type
$dg -> enable_export('EXCEL');
$dg -> enable_edit('FORM', 'CRUD');
$dg -> set_col_edittype('status', 'select', 'Open:Open;Shipped:Shipped;Cancelled:Cancelled;Disputed:Disputed;On Hold:On Hold');

// enable integrated search
$dg -> enable_search(true);
 
$dg -> display();

See Live Example!

It is possible to externalize search command using Javascript. Check out Externalize Search Example.

The post Integrated Search appeared first on phpGrid - PHP Datagrid.

]]>
505
Set Grid Height and Width https://phpgrid.com/example/set-height-and-width/ Thu, 16 Sep 2010 00:22:12 +0000 http://64.38.236.7/?p=507 Use set_dimension() method to specify grid initial height and width. The default height and width is 400 by 300 pixels. In this example, the width is set to 800 pixel, and height is set to 600 pixel. Wait, It looks funny! The grid height is taller than the space used by the number of rows […]

The post Set Grid Height and Width appeared first on phpGrid - PHP Datagrid.

]]>
Use set_dimension() method to specify grid initial height and width. The default height and width is 400 by 300 pixels. In this example, the width is set to 800 pixel, and height is set to 600 pixel.

Wait, It looks funny! The grid height is taller than the space used by the number of rows in a page. To fix this, we can set bigger pagination to accommodate a taller grid. See the next example on pagination.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");

// change column titles
$dg->set_col_title("orderNumber", "Order No.");
$dg->set_col_title("orderDate", "Order Date");
$dg->set_col_title("shippedDate", "Shipped Date");
$dg->set_col_title("customerNumber", "Customer No.");
 
// hide a column
$dg -> set_col_hidden("requiredDate");

// change default caption
$dg -> set_caption("Orders List");

// set export type
$dg -> enable_export('EXCEL');

// enable integrated search
$dg -> enable_search(true);

// set height and weight of grid
$dg -> set_dimension(800, 600);
 
$dg -> display();

See Live Example!

The post Set Grid Height and Width appeared first on phpGrid - PHP Datagrid.

]]>
507
Datagrid Pagination https://phpgrid.com/example/set-pagination/ Thu, 16 Sep 2010 00:24:36 +0000 http://64.38.236.7/?p=510 By default, the pagination size is 20. It means maximum of 20 records can be displayed in a page. This value can be easily changed with set_pagesize() method. Be aware that pagination is disabled when set_scroll() is set to true. See the next example on set_scroll() for more information. 12345678910111213141516171819202122232425262728293031// Always include namespace and conf.php […]

The post Datagrid Pagination appeared first on phpGrid - PHP Datagrid.

]]>
By default, the pagination size is 20. It means maximum of 20 records can be displayed in a page. This value can be easily changed with set_pagesize() method. Be aware that pagination is disabled when set_scroll() is set to true. See the next example on set_scroll() for more information.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");

// change column titles
$dg->set_col_title("orderNumber", "Order No.");
$dg->set_col_title("orderDate", "Order Date");
$dg->set_col_title("shippedDate", "Shipped Date");
$dg->set_col_title("customerNumber", "Customer No.");
 
// hide a column
$dg -> set_col_hidden("requiredDate");

// change default caption
$dg -> set_caption("Orders List");

// set export type
$dg -> enable_export('EXCEL');

// enable integrated search
$dg -> enable_search(true);

// set height and weight of datagrid
$dg -> set_dimension(800, 600);

// increase pagination size to 40 from default 20
$dg -> set_pagesize(40);
 
$dg -> display();

See Live Example!

The post Datagrid Pagination appeared first on phpGrid - PHP Datagrid.

]]>
510
Advanced Search https://phpgrid.com/example/advanced-search/ Thu, 16 Sep 2010 00:25:00 +0000 http://phpgrid.com/?p=2679 phpGrid also includes advanced search. By default, this feature is not enabled. To enable search use enable_advanced_search() method with parameter set to true. Once enabled, the advanced search can be toggled with the advanced search button on the footer. The advanced search can search on multiple fields simultaneously with different comparison operators. 1234567// Always include […]

The post Advanced Search appeared first on phpGrid - PHP Datagrid.

]]>
phpGrid also includes advanced search. By default, this feature is not enabled. To enable search use enable_advanced_search() method with parameter set to true. Once enabled, the advanced search can be toggled with the advanced search button on the footer.

The advanced search can search on multiple fields simultaneously with different comparison operators.

1
2
3
4
5
6
7
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/file/path/to/conf.php");  

$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");
$dg->enable_advanced_search(true);
$dg -> display();

See Live Example!

The post Advanced Search appeared first on phpGrid - PHP Datagrid.

]]>
2679