LaravelPackages.net
Acme Inc.
Toggle sidebar
iamtong/laravel-admin-grid-sortable

Sort the grid data by drag and drop rows

968
0
1.0
About iamtong/laravel-admin-grid-sortable

iamtong/laravel-admin-grid-sortable is a Laravel package for sort the grid data by drag and drop rows. It currently has 0 GitHub stars and 968 downloads on Packagist (latest version 1.0). Install it with composer require iamtong/laravel-admin-grid-sortable. Discover more Laravel packages by iamtong or browse all Laravel packages to compare alternatives.

Last updated

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

Star History Chart