PHP Classes

Render Table: Render HTML tables using list elements

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 301 All time: 7,409 This week: 140Up
Version License PHP version Categories
render-table 1.4GNU Lesser Genera...5.3HTML, PHP 5, GUI
Description 

Author

This class render HTML tables using list elements.

It takes an array of data and generates HTML UL and LI tags to display the data as list of rows and columns using a given CSS definition to make it render correctly as a table.

The class can receive columns that will be hidden but can be used for link building.

Rules can be defined to specify how to turn certain cells into external links that open on separate browser windows.

Innovation Award
PHP Programming Innovation award nominee
August 2014
Number 8


Prize: One copy of VS.PHP
HTML tables allow groups of page elements to be rendered in such way that they may be aligned both vertically and horizontally. However, HTML tables prevent that the elements layout be defined by separate CSS definitions.

This class provides an alternative solution to layout groups of page elements using HTML lists instead, i.e. it does not require using tables to align the page elements.

Manuel Lemos
Picture of Martin Barker
  Performance   Level  
Name: Martin Barker <contact>
Classes: 14 packages by
Country: United Kingdom
Age: 35
All time rank: 29414 in United Kingdom
Week rank: 164 Up6 in United Kingdom Up
Innovation award
Innovation award
Nominee: 2x

Example

<?php
/*
 * @author Martin Barker
 * @comment This system was built for zend framework however will work without
 * if this was in a Zend_Framework application $data could be an instance of
 * Zend_Db_Table_Abstract from a query
 */

// load required files
require_once("Singleton.php");
require_once(
"RenderTable.php");

// get new instance of class
$rt = RenderTable::GetInstance(true);

// setup some dummy data
// please note the use of case on the column names this is how they will be outputted however
// for CSS they will use a lowercase version spaces will be converted to _
// E.G ul.table li.row ul. li.web_site
$data = array(
    array(
       
"id" => 0,
       
"Name" => "Martin Barker",
       
"Age" => "25",
       
"webaddr" => "http://www.allheavymetal.net/",
       
"Profile" => "View Profile...",
       
"Web Site" => "Visit Site..."
   
),
    array(
       
"id" => 1,
       
"Name" => "Example User",
       
"Age" => "30",
       
"webaddr" => "http://www.example.com",
       
"Profile" => "View Profile...",
       
"Web Site" => "Visit Site"
   
)
);

// set the table title used for CSS ul.table.example_table
// second value is whether to show the title of the table or not
$rt->setTitle("Example Table", true);

// provide the data for rendering
$rt->setContent($data);

// set a href rule
// will detect :// and change to a _blank link for external links
// will use array and all rules append to the array
$rt->setHrefRule("Profile", "/view/profile/name/{Name}");
// you can also provide the rules as an array again these will be prepended to the rules array
$rt->setHrefRule(array(
   
"Web Site" => "{webaddr}"
));

// set hidden column
$rt->setHidden("id"); // will append to a list of columns so can be called multiple times
// or hide a set of columns again will append to list
$rt->setHidden(array(
   
"webaddr"
));

?>


  Files folder image Files (4)  
File Role Description
Accessible without login Plain text file demo.php Example Demo file showing how to use
Accessible without login Plain text file renderTable.css Data Basic CSS
Plain text file RenderTable.php Class TheMainClass
Plain text file Singleton.php Class Singleton instance class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:301
This week:0
All time:7,409
This week:140Up
User Comments (1)
Very nice post, thank you very much.
10 years ago (goodbee)
57%StarStarStar