承接 vkrtecek/table 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vkrtecek/table

Composer 安装命令:

composer require vkrtecek/table

包简介

Basic table builder.

关键字:

README 文档

README

License

The library focuses on easy table rendering of arrays of objects. No connections to database, only insert array.

License

The Table library is open-sourced software licensed under the MIT license.

Instalation

composer require vkrtecek/table

Examples

Let's say we have for all examples testing class like below:

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; }
}

Basic usage

If we want to render table with collection of TestObject, do:

$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');
                

The string passed by setContent() must be the same string as signature of property's getter without get. So for example if the TestObject has method getAge(), setContent() must pass string 'age' or 'Age'.

And in your View call:

<style>
    <?= $table->renderCSS(); ?>
</style>
.
.
.
<body>
    <?= $table->renderHTML(); ?>
</body>

or

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

so the result will look like

ID of personNameAge
1John38
2Susane35
3Paul13
4Joe25
5Lucia80
6Štěpán29

Advanced

Callbacks

We can specify a callback function instead of property name:

$table->addColumn('Name')->setContent(function (TestObject $obj) {
    return '<em class="red">' . $obj->getName() . '</em>';
});
ID of personNameAge
1John38
2Susane35
3Paul13
4John38
5Susane35
6Paul13

Sorting and filtering table data

Sometimes we need sort data by some attribute:

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

and now by clicking on the table column header, we can sort the rows by this column. Or setOrderable() pass one parameter of type callable to specify the style of sorting.

By typing code below the field for filtering of specific column data will appear:

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

If we don't want to show all rows and enable paging, which will render input for number of rows:

$table->enableListing();

Column class

Column can has it's own HTML class

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

Column filtering

Also for filtering by one single column, there is method setSoloSearchable() which pass string - URL attribute:

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

will after any table action show URL like http://my_Server/?...url_name=<value> and similar for date column

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

the URL will look like http://my_Server/?...url_from=<val_from>&url_to=<val_to> for filtering column by "between dates".

If one of these filters are set, the button for show/hide the navigation row will appear above the table. If the "SHOW" button is clicked, navigation row will appear as the second THEAD row.

Additional

If we want to sort and filter data by framework (e.g. QueryBuilder) and pass to table only filtered result set, call

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

and table skip sorting, filtering and paging. By this integer value is also counted number of pages in listing, so insert the right number.

If is need to customize URL, use method setNavigationNames like below:

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

will cause the URL will look after some table click action like http://my_Server/?cust_order_by=Name&cust_order=ASC&cust_limit=5&cust_page=1&cust_pattern=

Table is now multilingual and you can pass your own translations:

$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)
    ]
]);

统计信息

  • 总下载量: 58
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固