PHP Classes
elePHPant
Icontem

PHP DataGrid: Display data from arrays in sortable HTML tables

Recommend this page to a friend!
  Info   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2009-06-26 (7 years ago) RSS 2.0 feedNot enough user ratingsTotal: 3,028 This week: 1All time: 1,160 This week: 1,047Up
Version License PHP version Categories
php_datagrid 1.0.0BSD License5.0HTML, PHP 5
Description Author

This class can be used to display data from arrays in sortable HTML tables.

It traverses bidimensional arrays and shows its data in an HTML table.

The columns names in the table header row are configurable. The listing may be sorted when the user clicks on the header row cells. Custom columns may be added at the start or end of the table. The table presentation details may be configurable using CSS styles.

Picture of Nguyen Duc Thuan
Name: Nguyen Duc Thuan <contact>
Classes: 2 packages by
Country: Viet Nam Viet Nam

Details
Fete_ViewControl_DataGrid has been written by Nguyen Duc Thuan <me@ndthuan.com>. This class can be used to display a 2-dimensions array of data as a grid.

EXAMPLE INSTALLATION:

1.Create a mysql database:
    create database fetesample charset utf8 collate utf8_unicode_ci;
2. Import example.sql from command line:
    mysql -uyourmysqluser -pyourmysqlpassword fetesample < /path/to/example.sql;
3. Change connection params in example.php
4. Access example.php from a browser and see the outputs.

GETTING STARTED:

- GET THE GRID DISPLAYED
$rows = array(
    array('id' => '1', 'name' => 'A'),
    array('id' => '2', 'name' => 'B'),
    array('id' => '3', 'name' => 'C')
);
$grid = Fete_ViewControl_DataGrid::getInstance($rows);
$grid->setup(array(
    'id' => array('header' => 'ID')
    'name' => array('header' => 'Name')
))
->render();

ADVANCED USAGES:

- Variables that you can use within the cell template:
%data%          This variable will be replaced by the cell data itself
%counter%       This will be replaced by the row counter (the starting counter can be change by use setStartingCounter method)
$some_column$   This will be replaced by the value of the column on that row. For example, in the array above, $name$ can be A, B or C; $id$ can be 1, 2 or 3
[[someFunction:param1,param2,param3]] will be replaced by the value of someFunction('param1', 'param2', 'param3')

- TO ENABLE SORTING:
$grid->enableSorting(true);

- TO REMOVE A COLUMN:
$grid->removeColumn('id');

- TO CHANGE ALTERNATIVE ROWS CSS CLASS:
$grid->setAlterRowClass('someCssClass');

- TO ADD A CUSTOM COLUMN AFTER DATA COLUMNS:
$grid->addColumnAfter('column_name', 'cell template', 'column header', array_of_cell_attributes);
  Files folder image Files  
File Role Description
Plain text file DataGrid.php Class Main class
Accessible without login Plain text file example.php Example Example
Accessible without login Plain text file example.sql Data Sample Data
Accessible without login Plain text file README.txt Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 0%
Total:3,028
This week:1
All time:1,160
This week:1,047Up
User Comments (1)
Does everything the author claims it does.
2 years ago (Len Dozois)
72%StarStarStarStar