jdz/table
Composer 安装命令:
composer require jdz/table
包简介
A simple PHP Table generation library.
README 文档
README
A simple PHP library for generating HTML tables with ease.
Features
- 🎯 Simple and intuitive API
- 🎨 Support for custom styles and attributes
- 📊 Column width management
- 🔗 Colspan support
- 🔄 Fluent interface for method chaining
Requirements
- PHP 8.2 or higher
Installation
Install via Composer:
composer require jdz/table
Quick Start
use JDZ\Table\Table; // Create a table with headers $table = new Table(['Name', 'Age', 'City']); // Add rows $table->addRow(['John Doe', '30', 'New York']) ->addRow(['Jane Smith', '25', 'Los Angeles']); // Render the table echo $table->render();
Output:
<table> <thead> <tr> <td><strong>Name</strong></td> <td><strong>Age</strong></td> <td><strong>City</strong></td> </tr> </thead> <tbody> <tr> <td>John Doe</td> <td>30</td> <td>New York</td> </tr> <tr> <td>Jane Smith</td> <td>25</td> <td>Los Angeles</td> </tr> </tbody> </table>
Usage
Creating a Table
With String Headers
$table = new Table(['Column 1', 'Column 2', 'Column 3']);
With Custom Header Objects
use JDZ\Table\Th; $header1 = new Th('Name'); $header1->setStyle('color', 'blue'); $table = new Table([$header1, 'Age', 'Email']);
Adding Rows
Simple String Values
$table->addRow(['Alice', '28', 'alice@example.com']);
With Custom Cell Objects
use JDZ\Table\Td; $cell = new Td('Important'); $cell->setStyle('color', 'red') ->setAttribute('class', 'highlight'); $table->addRow([$cell, 'Data', 'More data']);
Setting Column Widths
$table->setColumnWidth(0, 50) // First column: 50% ->setColumnWidth(1, 25) // Second column: 25% ->setColumnWidth(2, 25); // Third column: 25%
Using Colspan
use JDZ\Table\Td; $spanningCell = new Td('This spans 2 columns', 2); $table->addRow([$spanningCell, 'Normal cell']);
Styling Cells
Adding CSS Classes
$cell = new Td('Content'); $cell->setAttribute('class', 'my-class');
Adding Inline Styles
$cell = new Td('Content'); $cell->setStyle('color', 'red') ->setStyle('font-weight', 'bold') ->setStyle('background-color', '#ffff99');
Adding Multiple Attributes
$cell = new Td('Content'); $cell->setAttribute('class', 'highlight') ->setAttribute('id', 'cell-1') ->setAttribute('data-value', '123');
Custom Headers
use JDZ\Table\Th; $header = new Th('Status'); $header->setWidth(20) // 20% width ->setStyle('color', 'blue') ->setAttribute('class', 'header-cell');
Complete Example
use JDZ\Table\Table; use JDZ\Table\Td; // Create table with headers $table = new Table(['Product', 'Price', 'Stock']); // Set column widths $table->setColumnWidth(0, 50) ->setColumnWidth(1, 25) ->setColumnWidth(2, 25); // Add rows with styled cells $priceCell = new Td('$999'); $priceCell->setStyle('color', 'green') ->setStyle('font-weight', 'bold'); $stockCell = new Td('Low'); $stockCell->setStyle('color', 'red'); $table->addRow(['Laptop', $priceCell, $stockCell]); $table->addRow(['Mouse', '$29', '150']); // Render echo $table; // Uses __toString() magic method
Testing
Run the test suite:
composer test
Run tests with detailed output:
vendor/bin/phpunit --testdox
Run tests with code coverage:
vendor/bin/phpunit --coverage-text
Examples
See the examples directory for more usage examples:
License
This library is licensed under the MIT License. See LICENSE file for details.
jdz/table 适用场景与选型建议
jdz/table 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「core」 「table」 「JDZ」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jdz/table 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jdz/table 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jdz/table 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Contao Open Source CMS
Plug-ins for DataTables
A component that allows creating responsive HTML tables or lists from data object
Adjacency List’ed Closure Table database design pattern implementation for Laravel. Includes restore of tree
DiZed Team Core module for the Magento 2 project
A simple package to create tables in Discord messages.
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-06