Looking to hire Laravel developers? Try LaraJobs

laravel-admin-grid-sortable maintained by iamtong

Description
Sort the grid data by drag and drop rows
Author
Last update
2019/12/06 06:48 (dev-master)
License
Downloads
968

Comments
comments powered by Disqus

laravel-admin grid-sortable

借鉴 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).