Dcat Admin 表格排序扩展

Laravel框架
526
0
0
2022-07-28

前言

前段时间使用了一下 Dcat Admin 框架,发现没有一款表格排序的插件,则查看 Dcat Admin 扩展开发文档,写了一个非常简单的表格排序扩展.

截图

Dcat Admin 表格排序扩展

使用

引入 composer 包

composer require xingchuangyang/dcat-admin-sortable

修改 Model

引入 SortableTrait,并实现 Sortable 接口

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;

class Product extends Model implements Sortable
{
    use SortableTrait;

    public $sortable = [
        'order_column_name' => 'sort',  // 排序字段  
        'sort_when_creating' => true,   // 新增是否自增,默认自增
    ];
}

在 Controller 中使用

$grid->column('sort', '排序')->action(\Xcy\DcatAdminSortable\Actions\SortableColumnRow::gen(\App\Models\Product::class));