Giter Site home page Giter Site logo

table's Introduction

Yet another very simple html table generator for PHP

composer require erguncaner/table dev-master

Generate a table structure as shown below

require_once __DIR__.'/vendor/autoload.php';

use erguncaner\Table\Table;
use erguncaner\Table\TableColumn;
use erguncaner\Table\TableRow;
use erguncaner\Table\TableCell;

// Sample data
$posts = [
    ['id'=>1, 'title'=>'Title 1'],
    ['id'=>2, 'title'=>'Title 2'],
    ['id'=>3, 'title'=>'Title 3'],
];

// First create a table
$table = new Table([
    'id'=>'post-table'
]);

// Create table columns with a column key and column object
$table->addColumn('id', new TableColumn('ID', ['class'=>'id-column']));
$table->addColumn('title', new TableColumn('TITLE'));

// Then add rows
foreach($posts as $post){
    
    // Associate cells with columns
    $cells = [
        'id' => new TableCell($post['id'], ['class'=>'id-cell']),
        'title' => new TableCell($post['title']),
    ];

    // define row attributes
    $attrs = [
        'id' => 'post-'.$post['id']
    ];

    $table->addRow(new TableRow($cells, $attrs));
}

// Finally generate html
$html = $table->html();

This will generate html below

<table id="post-table">
<thead>
    <tr><th class="id-column">ID</th><th>TITLE</th></tr>
</thead>
<tbody>
    <tr id="post-1"><td class="id-cell">1</td><td>Title 1</td></td>
    <tr id="post-2"><td class="id-cell">2</td><td>Title 2</td></td>
    <tr id="post-3"><td class="id-cell">3</td><td>Title 3</td></td>
</tbody>
<tfoot></tfoot>
</table>

table's People

Contributors

erguncaner avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.