PHP Data Grid

PHP Data Grid is a functional data grid. It allows you to define a grid with Create / Read / Update / Delete functionality. One of the main strengths of PHP Data Grid is that it provides only essential functionality. PHP Data Grid allows you to quickly build applications that are highly reliable with minimum effort. To minimise ongoing application maintenance and user training no features are provided to allow application users to customise the grid at run time. What you define is what users of your application will get. All you need to do is declare values for the grid to get all the functionality that you need in your application. If you want a highly customisable grid this is not for you. PHP Data Grid allows you to build functional and easy to use applications that work on desktop and mobile devices. PHP Data Grid is built to deliver consistently high applications performance and availability.

Demo

Download (Community Edition)

Requirements

Example PHP Code

Following is example PHP code to generate a grid to list vehicle parts. This example gives you Create / Read / Update / Delete functionality.

<?php
/**
 * @filename: parts.php
 * @description: This script contains logic to maintain vehicle parts.
 * @version: 1.0.0
 * @date: January 20, 2015
 * @author: Mark Cotugno
 * @copyright: Copyright 2015 Mark Cotugno. All rights reserved.
 * @history: 1.0.0 20150120 MDC First version.
 */
include_once('web.config.php');
include_once(
'grid.inc.v1.1.php');

/**
 *
 *
 */
function main()
{
    
$dg = new Uniform_DataGrid(array('hostname' => HOSTNAME,
                                     
'username' => USERNAME,
                                     
'userpassword' => USERPASSWORD,
                                     
'database' => DATABASE));

    
$dg->set_debug_mode_off();

    
$dg->list_query(array('query' => 'SELECT part_number, A.description, B.description AS part_description' .
                                     
' FROM part A LEFT JOIN part_type B ON A.part_type_number = B.part_type_number',
                          
'sort' => 'A.part_number ASC',
                          
'count_query' => 'SELECT COUNT(*) FROM part',
                          
'rows' => 5,
                          
'params' => array(),
                          
'form_params' => array('part_number'),
                          
'fields' => array('part_number''description''part_description'),
                          
'titles' => array('Part Number''Description''Type'),
                          
'widths' => array('100px''250px''150px'),
                          
'title' => 'View Parts'));

    
$dg->item_query(array('query' => 'SELECT part_number, description, part_type_number FROM part WHERE part_number = ?',
                          
'params' => array('part_number'),
                          
'types' => array('s'),
                          
'pattern' => array('''/^.*$/''/^.*$/'),
                          
'pattern_title' => array('''Description required''Part type required'),
                          
'fields' => array('part_number''description''part_type_number'),
                          
'field_type' => array('text''text''dropdown'),
                          
'lookup_query' => array('''''SELECT part_type_number, description FROM part_type ORDER BY description ASC'),
                          
'lookup_query_params' => array(array(), array(), array('part_type_number''description')),
                          
'mandatory' => array(TRUETRUETRUE),
                          
'form_params' => array('part_number'),
                          
'autocomplete' => array(FALSEFALSEFALSE),
                          
'readonly' => array(TRUEFALSEFALSE),
                          
'titles' => array('Part Number''Description''Type'),
                          
'widths' => array('100px''250px''150px'),
                          
'title' => 'Maintain Part'));

    
$dg->insert_query(array('query' => 'INSERT INTO part (part_number, description, part_type_number) VALUES (?, ?, ?)',
                            
'params' => array('part_number''description''part_type_number'),
                            
'types' => array('s''s''s'),
                            
'pattern' => array('''/^.*$/''/^.*$/'),
                            
'pattern_title' => array('''Description required''Part type required'),
                            
'fields' => array('part_number''description''part_type_number'),
                            
'field_type' => array('text''text''dropdown'),
                            
'lookup_query' => array('''''SELECT part_type_number, description FROM part_type ORDER BY description ASC'),
                            
'lookup_query_params' => array(array(), array(), array('part_type_number''description')),
                            
'mandatory' => array(TRUETRUETRUE),
                            
'validate' => array(),
                            
'autocomplete' => array(FALSEFALSEFALSE),
                            
'readonly' => array(TRUEFALSEFALSE),
                            
'gen_value_functions' => array('get_next_part_number'NULLNULL),
                            
'titles' => array('Part Number''Description''Type'),
                            
'widths' => array('100px''250px''150px'),
                            
'title' => 'Add New Part'));

    
$dg->update_query(array('query' => 'UPDATE part SET description = ?, part_type_number = ? WHERE part_number = ?',
                            
'params' => array('description''part_type_number''part_number'),
                            
'types' => array('s''s''s'),
                            
'pattern' => array('''/^.*$/''/^.*$/'),
                            
'pattern_title' => array('''Description required''Part type required'),
                            
'fields' => array('part_number''description''part_type_number'),
                            
'field_type' => array('text''text''dropdown'),
                            
'lookup_query' => array('''''SELECT part_type_number, description FROM part_type ORDER BY description ASC'),
                            
'lookup_query_params' => array(array(), array(), array('part_type_number''description')),
                            
'mandatory' => array(TRUETRUETRUE),
                            
'validate' => array(),
                            
'title' => 'Part Updated'));

    
$dg->delete_query(array('query' => 'DELETE FROM part WHERE part_number = ?',
                            
'params' => array('part_number'),
                            
'types' => array('s'),
                            
'title' => 'Part Deleted'));

    
$dg->set_locale('en');

    echo 
$dg->to_html();
}

/**
 *
 *
 */
function get_next_part_number()
{
    
$dg = new Uniform_DataGrid(array('hostname' => HOSTNAME,
                                     
'username' => USERNAME,
                                     
'userpassword' => USERPASSWORD,
                                     
'database' => DATABASE));

    
$dg->get_next_counter_id($bb_counterValue_bb'counters''part_number''PN');

    return 
$bb_counterValue_bb;
}

/**
 *
 *
 */
main();
?>

Example MySQL Database Tables

Following is example MySQL queries to generate tables for a grid to list vehicle parts. This example gives you Create / Read / Update / Delete functionality.

delimiter $$

CREATE TABLE `part_type` (
`part_type_number` char(15) NOT NULL,
`description` varchar(45) DEFAULT NULL,
PRIMARY KEY (`part_type_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8$$


delimiter $$

CREATE TABLE `part` (
`part_number` char(15) NOT NULL,
`description` varchar(45) DEFAULT NULL,
`part_type_number` char(15) DEFAULT NULL,
PRIMARY KEY (`part_number`),
KEY `part_type_number_idx` (`part_type_number`),
CONSTRAINT `part_type_number_idx` FOREIGN KEY (`part_type_number`) REFERENCES `part_type` (`part_type_number`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8$$


delimiter $$

CREATE TABLE `counters` (
`counter_name` char(50) NOT NULL,
`counter_value` int(11) DEFAULT '0',
PRIMARY KEY (`counter_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8$$


INSERT INTO `counters`
(`counter_name`,
`counter_value`)
VALUES
(
'part_number',
900000000
);

INSERT INTO `counters`
(`counter_name`,
`counter_value`)
VALUES
(
'part_type_number',
900000000
);

License (Community Edition)

PHP Data Grid Community Edition is the freely downloadable version of PHP Data Grid. It is available under the GPL license.

Copyright

Copyright Mark Cotugno 2015-2016. All Rights Reserved