Skip to content

jspit-de/Table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTML table builder

A PHP class for building an HTML table with data from a 2 dimensional array

Features

  • Use Table-Values from Arrays, Objects how PDO-Statement and Iterators
  • Add Title from Array, first Data Line or Array-Keys
  • Add Attributes how name, css-class for styling
  • Handles context switching for HTML
  • Formatting values with sprintf-Formats or date-Formats
  • One class and One File

Usage

require '/yourpath/Table.php';  //or autoload

$data = [  
  ['name' => 'A1', 'value' => 3],  
  ['name' => 'A12', 'value' => 6],  
  ['name' => 'A2','value' => 14],  
  ['name' => 'A14','value' => 7],  
]; 
$table = Table::create($data) 
  ->title(['Name','Wert']) 
  ->getHtml() 
; 
//Output
echo $table;

Demo and Test

http://jspit.de/check/phpcheck.table.php

Requirements

  • PHP 5.6 .. 8.2

Class-Info

Info Value
Declaration class Table
Datei Table.php
Date/Time modify File 2023-04-16 11:15:58
File-Size 7452 Byte
MD5 File d531c208b9a7bf2fb554d6e204c7bf18
Version 1.4
Date 2023-04-16

Public Methods

Methods and Parameter Description/Comments
final public function __construct($data) @param mixed $data : array, object, iterator
public static function create($data) create a instance
@param mixed $data : 2 dim array, iterator or tableArray Instance
@return static instance of tableArray
public function attribute($list) set html-Attributes
@param string $list: css-class-name or attribute-list
@return $this
public function title($title) set titles for columns
@param mixed $title
$title: Table::KEY, Table::FIRSTLINE, array or string with comma as delimiter
@return $this
public function format(array $format) set format for every column
may use sprintf-formats and date/datetime-formats
@param array $format:
@return $this
public function quoteSpecialChars($boolArr) set a mask if quote html special chars
@param array $boolArr: array with true/false (default all true)
@return $this
public function colClassName($className) @param string $className: className for Colums
@return $this
public function rowClassName($className) @param string $className: className for rows
@return $this
public function getHtml() render and get HTML
@return string : html
public function __toString() Return HTML for the table
@return string

Constants

Declaration/Name Value Description/Comments
const FIRSTLINE = 4; //title -> first Line data 4 title -> first Line data
const KEY = 8; //title -> keys from subarray 8 title -> keys from subarray

About

HTML Table Builder

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages