lloricode/laravel-html-table
Composer 安装命令:
composer require lloricode/laravel-html-table
包简介
Html table generator for laravel
README 文档
README
Generate Html Table with data from array/object.
Installation
You can install the package via composer:
composer require lloricode/laravel-html-table
Usage
Sample in view
$headers = ['col1', 'col2']; $data = [ [ 'Lloric', 'Garcia', ], [ 'Foo', 'Bar', ], [ 'Foo1', 'bar11', ], [ 'tst', 'tesss', ], ]; $attributes = 'class="table"'; // Or $attributes = ['myclass' => 'test_val']; {!! Table::generate($headers, $data) !!} {!! Table::generate($headers, $data, $attributes) !!} // Model way {!! Table::generateModel( ['Id', 'Name', 'Email'], // Column for table 'App\User' // Model ,['id', 'name', 'email'], // Fields from model 0, // Pagination Limit, if 0 all will show 'border="1"' // Attributes sample js/css ) !!} {{ Table::links() }} // Generate this when limit is not 0 // then you can add a links {!! Table::optionLinks('my.route.name') ->modelResult(function($query){ // you can add filter if you are using model generate $query->where('user_id', auth()->user()->id); return $query; }) ->generateModel( ['Id', 'Name', 'Email'], // Column for table 'App\User' // Model ,['id', 'name', 'email'], // Fields from model 5, // Pagination Limit, if 0 all will show 'border="1"' // Attributes sample js/css ) !!} // you can specify more args // 1st route name, 2nd header label, and 3rd is the every row label {!! Table::optionLinks('my.route.name', 'my option', 'view') ->generateModel( ['Id', 'Name', 'Email'], // Column for table 'App\User' // Model ,['id', 'name', 'email'], // Fields from model 5, // Pagination Limit, if 0 all will show 'border="1"' // Attributes sample js/css ) !!}
This is all default values html tags
$attributes = [ // Main Table 'table' => '<table>', 'table_end' => '</table>', // Head 'head' => '<thead>', 'head_end' => '</thead>', 'head_row' => '<tr>', 'head_row_end' => '</tr>', 'head_cell' => '<th>', 'head_cell_end' => '</th>', // Data body 'body' => '<tbody>', 'body_end' => '</tbody>', 'body_row' => '<tr>', 'body_row_end' => '</tr>', 'body_cell' => '<td>', 'body_cell_end' => '</td>', // Alternative 'alt_body_row' => '<tr>', 'alt_body_row_end' => '</tr>', 'alt_body_cell' => '<td>', 'alt_body_cell_end' => '</td>', ]; {!! Table::generate($headers, $data, $attributes) !!}
Sample Output
<table myclass="test_val"><thead><tr><th>col1</th><th>col2</th></tr></thead><tbody><tr><td>Lloric</td><td>Garcia</td></tr><tr><td>Foo</td><td>Bar</td></tr><tr><td>Foo1</td><td>bar11</td></tr><tr><td>tst</td><td>tesss</td></tr></tbody></table>
Adding attributes in cell data
$header = ['Date', 'Description', 'Amount']; $datas = [ [ ['data' => '1', 'scope' => 'row'], 'Mark', 'Otto', ], [ ['data' => '2', 'scope' => 'row'], 'foo', 'varr', ], ]; {!! Table::generate($header, $datas, ['class'=>'table']) !!} <table class="table"> <thead> <tr> <th>Date</th> <th>Description</th> <th>Amount</th> </tr> </thead> <tbody> <tr> <td scope="row">1</td> <td>Mark</td> <td>Otto</td> </tr> <tr> <td scope="row">2</td> <td>foo</td> <td>varr</td> </tr> </tbody> </table>
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
lloricode/laravel-html-table 适用场景与选型建议
lloricode/laravel-html-table 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66.55k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2017 年 07 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 lloricode/laravel-html-table 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lloricode/laravel-html-table 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 66.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-07-19