承接 andydune/html-table 相关项目开发

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

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

andydune/html-table

Composer 安装命令:

composer require andydune/html-table

包简介

This code will simplify or improve your work with html tables.

关键字:

README 文档

README

This code will simplify or improve your work with html tables.

Build Status Software License Packagist Version Total Downloads

Requirements

PHP version >= 5.6

Installation

Installation using composer:

composer require andydune/html-table

Or if composer was not installed globally:

php composer.phar require andydune/html-table

Or edit your composer.json:

"require" : {
     "andydune/html-table": "^1"
}

And execute command:

php composer.phar update

Example

Here is small part of code for drawing html table with dynamic data.

<table class="table authlog">
    <thead>
    <tr>
        <td>ID</td>
        <td>User</td>
        <td>STATUS</td>
        <td>Created</td>
        <td>Updated</td>
        <td>Uploaded</td>
        <td>Link</td>
        <td>Data</td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
    </thead>
    <tbody>
    <?php foreach ($list as $file) {
        ?>
        <tr class="<?= $file->getStatus() == 2 ? 'table-success' : null; ?>">
            <td><?= $file->getId(); ?></td>
            <td><?= $user['EMAIL'] ?> (<?= $user['XML_ID'] ?>)</td>
            <td><?= $showStatus($file->getStatus()); ?></td>
            <td><?= $file->getData('DATETIME'); ?></td>
            <td><?= $file->getData('DATETIME_UPDATE'); ?></td>
            <td><?= $file->getData('DATETIME_LAST_REQUEST'); ?></td>
            <td><?= $file->getFileName(); ?>.<?= $file->getFileType() ?></td>
            <td><? $showArray($file->getMeta()) ?></td>
            <td></td>
            <td>повтор</td>
            <td>удаление</td>
        </tr>
    <?php } ?>
    </tbody>
</table>

It is simple to accidentally break html by removing single tag. And it is difficult to read and change.

There is better code down below:

use AndyDune\HtmlTable\Builder;
use AndyDune\HtmlTable\Table;

$table = new Table();
$head = $table->head();
$head->cell()->setContent('ID');
$head->cell()->setContent('User');
$head->cell()->setContent('STATUS');
$head->cell()->setContent('Created');
$head->cell()->setContent('Updated');
$head->cell()->setContent('Uploaded');
$head->cell()->setContent('Uploaded');
$head->cell()->setContent('Data');
// Empty cells will be added automatically depends on max cell count for next rows.
foreach ($list as $file) {
    $row = $table->row();
    if ($file->getStatus() == 2) {
        $row->addClass('table-success')
    }
    $row->cell()->setContent($file->getId());
    $row->cell()->setContent($user['EMAIL'] . $user['XML_ID']);
    $row->cell()->setContent($showStatus($file->getStatus()));
    $row->cell()->setContent($file->getData('DATETIME'));
    $row->cell()->setContent($file->getData('DATETIME_UPDATE'));
    $row->cell()->setContent($file->getData('DATETIME_LAST_REQUEST'));
    $row->cell()->setContent($file->getFileName() . '.' . $file->getFileType());
    $row->cell()->setContent($showArray($file->getMeta()));
}

$buider = new Builder($table);
$builder->setGroupingSections(true);
echo $buider->getHtml(); 

Class structure

Table structure is reflect by classes:

  • AndyDune\HtmlTable\Table - a root of the structure

  • AndyDune\HtmlTable\Element\Row - it implements a table row

  • AndyDune\HtmlTable\Element\Head - it implements a special table row (head). It can be only one.

  • AndyDune\HtmlTable\Element\Cell - it implements a table cell. It is a part of Row (Head)

  • AndyDune\HtmlTable\Builder - the root class for building html code for table. It receives Table instance as a construct parameter.

  • There are many assistive classes for building table, but you don't need to know about their.

Describe table

Table may have attributes, data rows, head row. Rows and cells may have attributes too.

Table, row, cell class attribute

Use method addClass to inject class into table element. Element may have many classes:

use AndyDune\HtmlTable\Table;

// Set classes *useful* and  *one* to table.
$table = new Table();
$table->addClass('useful')->addClass('one');
$table->getClasses(); ['useful', 'one]
// <table class="useful one">

// Set class *active* to row.
$row = $table->row();
$row->addClass('active');
// <tr class="active">

// Set class *left* to cell.
$cell = $row->cell();
$row->addClass('left');
// <td class="left">

Table, row, cell id attribute

Use method setId to inject id into table element. Element may have only one id:

use AndyDune\HtmlTable\Table;

// <table id="top">
$table = new Table();
$table->setId('top');
$table->getId(); // top

// <tr id="active">
$row = $table->row();
$row->setId('active');
$row->getId(); // active

// <td id="left">
$cell = $row->cell();
$row->setId('left');
$row->getId(); //left

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-04-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固