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));
本作品采用《CC 协议》,转载必须注明作者和本文链接
关于 LearnKu
粤公网安备 44030502004330号
很棒。
该排序是对Dcat1.x版本开发的吗?在2.x上点击排序按钮会显示404Not Found,行操作应该是不需要额外定义路由的才对
似乎不能用?
可以用,进入dcat后台,拓展-》启用一下就可以
请求 URL: meeting.cn/admin/xcyDcatAdmin/sorta... 请求方法: POST 状态代码: 404 Not Found 远程地址: 127.0.0.1:31181 引用站点策略: no-referrer 这个路由需要自己单独写吗
Illegal operator and value combination