PHP code example of vkrtecek / table

1. Go to this page and download the library: Download vkrtecek/table library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vkrtecek / table example snippets


class TestObject
{
    private $id;
    private $name;
    private $age;
    private $birthdate;
    
    public function __construct($id, $name, $age, $birthdate = NULL) {
        $this->id = $id;
        $this->name = $name;
        $this->age = $age;
    }
    
    public function getId() { return $this->id; }
    public function getName() { return $this->name; }
    public function getAge() { return $this->age; }
    public function getBirthDate() { return $this->birthdate; }
}

$data = [
    new TestObject(1, 'John', 38),
    new TestObject(2, 'Susane', 35),
    new TestObject(3, 'Paul', 13),
    new TestObject(4, 'Joe', 25),
    new TestObject(5, 'Lucia', 80),
    new TestObject(6, 'Štěpán', 29, '1989-03-23'),
];

$table = \Vkrtecek\Table\Table::create($data)
   ->addColumn('ID of person')->setContent('id')
   ->addColumn('Name')->setContent('name')
   ->addColumn('Age')->setContent('age');
                

<style>
    <?= $table->renderCSS(); 

$table->renderHTML(['css' => true]);

$table->addColumn('Name')->setContent(function (TestObject $obj) {
    return '<em class="red">' . $obj->getName() . '</em>';
});

$table->addColumn('Name')->setOrderable()->setContent('name');

$table->addColumn('Name')->setSearchable()->setContent('name');

$table->enableListing();

$table->addColumn('ColName')->setClass('red');

$table->addColumn('Name')->setSoloSearchable('url_name')->setContent('name');

$table->addColumn('Name')->setDateFromToSearchable('url_from', 'url_to')->setContent('birthade');

$table = Table::create($rows)->setTotalItemCount(count($rows));

$table->setNavigationNames([
    'limit' => 'cust_limit',
    'orderBy' => 'cust_order_by',
    'order' => 'cust_order',
    'page' => 'cust_page',
    'pattern' => 'cust_pattern',
    'url' => 'my_Server'
])

$table->renderHTML([
    'translations => [
        'Show navigation bar' => [string],  //button content
        'Hide navigation bar' => [string],  //button content
        'Search by' => [string],            //above table input's content
        'From' => [string],                 //in navigation row for dates
        'To' => [string],                   //in navigation row for dates
        'pattern' => [string],              //in navigation row for string searches
        'of' => [string],                   //in status bar (1 - 15 of 365)
    ]
]);