iamtong / laravel-admin-grid-sortable
Sort the grid data by drag and drop rows
1.0
2019-12-06 05:48 UTC
Requires
- php: >=7.0.0
- encore/laravel-admin: >=1.7.2
- spatie/eloquent-sortable: *
Requires (Dev)
- phpunit/phpunit: ~6.0
This package is auto-updated.
Last update: 2025-05-06 17:40:01 UTC
README
借鉴 https://github.com/laravel-admin-extensions/grid-sortable 修改,主要为了让laravel可以使用路由缓存
Installation
composer require iamtong/laravel-admin-grid-sortable -vvv
Publish asserts
php artisan vendor:publish --provider="iamtong\LaravelAdmin\GridSortable\GridSortableServiceProvider"
Usage
Define your model
<?php use Illuminate\Database\Eloquent\Model; use Spatie\EloquentSortable\Sortable; use Spatie\EloquentSortable\SortableTrait; class MyModel extends Model implements Sortable { use SortableTrait; public $sortable = [ 'order_column_name' => 'order_column', 'sort_when_creating' => true, ]; }
Use in grid
$grid = new Grid(new MyModel); $grid->sortable();
This will add a column to the grid. After dragging one row, a Save order
button will appear at the top of the grid. Click to save order.
Translation
The default text for the button is Save order
. If you use an other language, such as Simplified Chinese, you can add a translation to the resources/lang/zh-CN.json
file.
{ "Save order": "保存排序" }
License
Licensed under The MIT License (MIT).