定制 greystoneweb/livewire-datatables 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

greystoneweb/livewire-datatables

最新稳定版本:0.1.5

Composer 安装命令:

composer require greystoneweb/livewire-datatables

包简介

README 文档

README

Introduction

Basic Example

Using the make command: php artisan make:datatable Users/UsersTable

Will create two files: Users/UsersTable.php and users/users-table-row.blade.php in your Livewire directories.

Features

Sorting

To enable sorting just call the sortable() method on a column.

public function columns(): array
{
    return [
        Column::make('Name')
            ->sortable()
    ];
}

If the column header label differs from the database column, be sure to specify it with the second parameter in the make() method.

Column::make('Name', 'full_name')
    ->sortable()

If you need any custom sort logic to be applied, you can pass a callback to the sortable() method.

Column::make('Name')
    ->sortable(function ($query, $direction) {
        $query->orderBy('last_name', $direction);
    })

Filters

Search

Exporting Results

To use this feature, you'll have to install Laravel Excel.

Example:

Inside your component class:

use Greystoneweb\LivewireDataTables\DataTable;
use Greystoneweb\LivewireDataTables\Traits\Exportable;

class UsersTable extends DataTable
{
    // Use the Exportable trait
    use Exportable;

    // Define a fileName method that returns the filename
    protected function fileName(): string
    {
        return 'users'.date('Y-m-d').'.csv';
    }
    ...
}

And then you can call the export() method from your view with wire:click and all of the results will be automatically be exported to CSV with filters/sorts applied. If the exported file doesn't look quite right, you can create a custom Export instance that extends Greystoneweb\LivewireDataTables\Export and return it in a method called exporterInstance on the datatable component. This is particularly useful when dealing with relationships.

Example:

Your component:

use Greystoneweb\LivewireDataTables\DataTable;
use Greystoneweb\LivewireDataTables\Export;
use Greystoneweb\LivewireDataTables\Traits\Exportable;

class UsersTable extends DataTable
{
    // Use the Exportable trait
    use Exportable;

    // Define a fileName method that returns the filename
    protected function fileName(): string
    {
        return 'users'.date('Y-m-d').'.csv';
    }

    public function exporterInstance(): Export
    {
        return new UsersExport($this);
    }
    ...
}

Your custom exporter:

use Greystoneweb\LivewireDataTables\Export;
use Maatwebsite\Excel\Concerns\WithMapping;

class UsersExport extends Export implements WithMapping
{
    public function headings(): array
    {
        return [
            'Name',
            'Organization',
            'Email',
        ];
    }

    public function map($user): array
    {
        return [
            $user->name,
            $user->organization->name,
            $user->email,
        ];
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-19