am2studio / laravel-table-sorter
Laravel table sorter
Installs: 4 775
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 7
Forks: 2
Open Issues: 0
Requires
- php: >=5.4.0
- laravel/framework: 5.2.*
This package is not auto-updated.
Last update: 2024-12-21 19:11:22 UTC
README
Package contains helper function for creating sortable colums in table
Install
Via Composer
$ composer require am2studio/laravel-table-sorter
Usage
Code in view :
{{ \AM2Studio\Laravel\TableSorter\TableSorter::sort( [ ['name' => 'first_name', 'title' => trans('ui.user.first_name')], ['name' => 'last_name', 'title' => trans('ui.user.last_name')], ['name' => 'gender', 'title' => trans('ui.user.gender')], ], $users, [ 'sort_by' => 'name', 'sort_type' => 'ASC', 'template' => '<th class="%s"><a href="%s">%s</a></th>' ]) }}
variable $headings contains name and title for table columns, example for users
[ ['name' => 'first_name', 'title' => trans('ui.user.first_name')], ['name' => 'last_name', 'title' => trans('ui.user.last_name')], ['name' => 'gender', 'title' => trans('ui.user.gender')], ]
variable $config contains default sort_by/sort_type and template
[ 'sort_by' => 'name', 'sort_type' => 'ASC', 'template' => '<th class="%s"><a href="%s">%s</a></th>' ]
Controller code:
public function index() { $users = (new User)->paginate(10); return $this->view('index', compact('users')); }
Full view table :
<table> <thead> <tr> {{ \AM2Studio\Laravel\TableSorter\TableSorter::sort( [ ['name' => 'first_name', 'title' => trans('ui.user.first_name')], ['name' => 'last_name', 'title' => trans('ui.user.last_name')], ['name' => 'gender', 'title' => trans('ui.user.gender')], ], $users, [ 'sort_by' => 'name', 'sort_type' => 'ASC', 'template' => '<th class="%s"><a href="%s">%s</a></th>' ]) }} </tr> </thead> <tbody> @foreach($users as $user) <tr> <td>{{ $user->first_name }}</td> <td>{{ $user->last_name }}</td> <td>{{ $user->gender }}</td> </tr> @endforeach </tbody> </table> <div>{!! $users !!}</div>
Change log
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING and CONDUCT for details.
License
The MIT License (MIT). Please see License File for more information.