承接 coryrose/livewire-tables 相关项目开发

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

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

coryrose/livewire-tables

Composer 安装命令:

composer require coryrose/livewire-tables

包简介

An extension for Livewire that allows you to effortlessly scaffold datatables with optional pagination, search, and sort.

README 文档

README

Latest Version on Packagist Total Downloads Build Status StyleCI

An extension for Livewire that allows you to effortlessly scaffold datatables with optional pagination, search, and sort.

Live demo website will be available soon.

Installation

Via Composer

$ composer require coryrose/livewire-tables

The package will automatically register its service provider.

To publish the configuration file to config/livewire-tables.php run:

php artisan vendor:publish --provider="Coryrose\LivewireTables\LivewireTablesServiceProvider"

Usage

Livewire tables are created in three simple steps:

  1. Create a table component class
  2. Configure the table class using the available options
  3. Scaffold the table view (as needed when component class changes)

Create a table component class

Run the make command to generate a table class:

php artisan livewire-tables:make UsersTable

App/Http/Livewire/Tables/UsersTable.php

...

class UsersTable extends LivewireModelTable
{
    use WithPagination;
    
        public $paginate = true;
        public $pagination = 10;
        public $hasSearch = true;
    
        public $fields = [
            [
                'title' => 'ID',
                'name' => 'id',
                'header_class' => '',
                'cell_class' => '',
                'sortable' => true,
            ],
            [
                'title' => 'Name',
                'name' => 'name',
                'header_class' => '',
                'cell_class' => '',
                'sortable' => true,
                'searchable' => true,
            ],
            [
                'title' => 'City',
                'name' => 'address.city',
                'header_class' => 'bolded',
                'cell_class' => 'bolded bg-green',
                'sortable' => true,
                'searchable' => true,
            ],
            [
                'title' => 'Post',
                'name' => 'post.content',
                'header_class' => '',
                'cell_class' => '',
                'sortable' => true,
                'searchable' => true,
            ],
        ];
    
        public function render()
        {
            return view('livewire.tables.users-table', [
                'rowData' => $this->query(),
            ]);
        }
    
        public function model()
        {
            return User::class;
        }
    
        public function with()
        {
            return ['address', 'post'];
        }
}

Configure the component options

First, set your base model in the model() method in the following format:

public function model()
{
    return User::class;
}

To eager load relationships, use the with() and return an array of relation(s):

public function with()
{
    return ['address', 'post'];
}

The following are editable public properties for the table class:

key description value default
$paginate Controls whether the data query & results are paginated. If true, the class must use WithPagination; bool true
$pagination The number value to paginate with integer 10
$hasSearch Controls global appearance of search bar bool true
$fields The fields configuration for your table array null
$css Per-table CSS settings array null

$fields

Controls the field configuration for your table

key description value
title Set the displayed column title string
name Should represent the database field name. Use '.' notation for related columns, such as user.address string
header_class Set a class for the <th> tag for this field string or null
cell_class Set a class for the <td> tag for this field string or null
sortable Control whether or not the column is sortable bool or null
searchable Control whether or not the column is searchable bool or null

$css

Used to generate CSS classes when scaffolding the table.

These can be set globally in the configuration file, or on a per-table basis in the component class.

Note: CSS classes set in the component will override those from the configuration file where both exist.

key description value
wrapper CSS class for <div> surrounding table string or null
table CSS class for <table> string or null
thead CSS class for <thead> string or null
th CSS class for <th> string or null
tbody CSS class for <tbody> string or null
tr CSS class for <tr> string or null
td CSS class for <td> string or null
search_wrapper CSS class for <div> surrounding search string or null
search_input CSS class for search <input> string or null
pagination_wrapper CSS class for <div> surrounding pagination buttons string or null

Scaffold the table view

When ready, scaffold the table view using the scaffold command:

php artisan livewire-tables:scaffold UsersTable

resources/views/livewire/tables/users-table.blade.php

<div>
    @if ($hasSearch)
    <div>
        <div style="position: relative; display: inline-block;">
        <input type="text" wire:model="search" />
            @if ($search)
                <button wire:click="clearSearch" style="position: absolute; right: 5px;">&#10005;</button>
            @endif
        </div>
    </div>
    @endif
    <table class="table-wrapper">
        <thead>
        <tr>
            <th class="header" wire:click="$emit('sortColumn', 0)">ID</th>
            <th class="header" wire:click="$emit('sortColumn', 1)">Name</th>
            <th class="header bolded" wire:click="$emit('sortColumn', 2)">City</th>
            <th class="header" wire:click="$emit('sortColumn', 3)">Post</th>
        </tr>
        </thead>
        <tbody>
        @foreach ($rowData as $row)
            <tr>
                <td class="table-cell">{{ $row->id }}</td>
                <td class="table-cell">{{ $row->name }}</td>
                <td class="table-cell bolded bg-green">{{ $row->address->city }}</td>
                <td class="table-cell">{{ $row->post->content }}</td>
            </tr>
        @endforeach
        </tbody>
    </table>
    @if ($paginate)
    <div>
        {{ $rowData->links() }}
    </div>
    @endif
</div>

You can use the scaffold command continuously as you make changes to the parent component class.

Since the rendered template is simple HTML, there’s no need for table “slots” for customization - customize the template as you see fit!

Todo

  • Further support for more advanced queries than a model

Change log

Please see the changelog for more information on what has changed recently.

Contributing

Please see contributing.md for details and a todolist.

Credits

License

MIT. Please see the license file for more information.

coryrose/livewire-tables 适用场景与选型建议

coryrose/livewire-tables 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41.45k 次下载、GitHub Stars 达 88, 最近一次更新时间为 2019 年 11 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「livewire」 「livewire-tables」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 coryrose/livewire-tables 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 coryrose/livewire-tables 我们能提供哪些服务?
定制开发 / 二次开发

基于 coryrose/livewire-tables 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 88
  • Watchers: 2
  • Forks: 19
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-02