To Create DataGridView in PHP you need phpGrid. If you are new to phpGrid, we recommend that you go through the examples in the sequence provided for each section. First download phpGrid.
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 1.9.0.
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.
A Basic DataGridView in PHP
The basic datagridview in php requires only as little as TWO lines of code. Foremostly, always create phpGrid object in the first line; then call its methods to define properties, and lastly always call display() to render to screen.
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.
- parameter 1: SQL statement
- parameter 2: SQL primary key
- parameter 3: SQl table name
1 2 |
$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders"); $dg -> display(); |
Descriptive Column Headers
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 |
$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(); |
Hide Column
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 datagridview and form, set the second parameter to false. This is useful to hide the auto increment primary key field from edit form.
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.
1 2 3 4 5 6 7 8 9 10 11 12 |
$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(); |
there are more options you can configure which is explained in documentation of phpGrid. If you find any difficulty configure phpGrid for more option please let us know by submit query in contact page. We are happy to help you. For more updates like our FB Page.