承接 cakmalik/livewire-generic-table 相关项目开发

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

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

cakmalik/livewire-generic-table

最新稳定版本:v1.0.10

Composer 安装命令:

composer require cakmalik/livewire-generic-table

包简介

A reusable and customizable generic table component for Livewire 3.

README 文档

README

A flexible, Volt-friendly, and fully customizable table component for Laravel Livewire v3.
Designed for reusable admin tables with sorting, searching, actions, pagination, and custom column formatting.

🚀 Features

  • Works with both Livewire and Livewire Volt
  • Fully customizable column configuration array
  • Searchable and sortable columns
  • Badge formats with dynamic colors & labels
  • Image, badge, datetime, link, and custom renderers
  • Row actions with event emission
  • Pagination with configurable per‑page options
  • Easy integration into any Laravel app or package

📦 Installation

Install via Composer:

composer require your-vendor/generic-table

If using Laravel < 10.21, publish views:

php artisan vendor:publish --tag=livewire-generic-table-views

🧩 Usage

In Blade

<livewire:generic-table
    :model="'App\\Models\\Post'"
    :columns="$columns"
    :queryParams="['keyword' => request('keyword')]"
    defaultSortField="created_at"
    defaultSortDirection="desc"
/>

In Volt

Because Volt does not allow nested arrays inside state, you must use a computed property:

#[Computed]
public function columns(): array
{
    return [
        [
            'label' => 'Title',
            'field' => 'title',
            'sortable' => true,
            'searchable' => true,
        ],
        [
            'label' => 'Status',
            'field' => 'status',
            'format' => 'badge',
            'badge' => [
                'colors' => [
                    'draft' => 'bg-gray-100 text-gray-700',
                    'published' => 'bg-green-100 text-green-800',
                ],
                'labels' => [
                    'draft' => 'Draft',
                    'published' => 'Published',
                ],
                'default' => 'bg-gray-200 text-gray-900',
                'default_label' => 'Unknown',
            ],
        ],
    ];
}

Then use it:

<livewire:generic-table
    :model="$this->modelName"
    :columns="$this->columns"
    :queryParams="[
        'keyword' => request('keyword')
    ]"
/>

🛠 Column Options

Each column supports:

Key Description
label Column header text
field Column data field (supports nested relation.field)
sortable Enable sorting
searchable Enable keyword searching
format text, image, badge, datetime, custom
badge Configuration for badge colors & labels
actions Row action buttons

Example with actions

[
    'label' => 'Actions',
    'field' => 'actions',
    'actions' => [
        [
            'event' => 'editAction',
            'icon' => 'pencil',
            'color' => 'indigo',
            'variant' => 'primary',
        ],
        [
            'event' => 'deleteAction',
            'icon' => 'trash',
            'color' => 'red',
            'variant' => 'danger',
        ],
    ],
],

📡 Events

Your component may listen to row action events:

#[On('editAction')]
public function edit($id)
{
    // handle edit
}

🎨 Custom Styling

You may override the view:

php artisan vendor:publish --tag=generic-table-views

Then edit:

resources/views/vendor/generic-table/generic-table.blade.php

🤝 Contributing

Pull requests are welcome!
If you want to improve functionality, fix bugs, or extend features—feel free to contribute.

📜 License

This package is open-sourced under the MIT License.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-08