marmarait / laraveldynamicsort
Lets you sort your Models dynamically by querystring
Installs: 222
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:libary
This package is not auto-updated.
Last update: 2025-05-16 10:18:45 UTC
README
Overview
Simply sort your Models by using querystring parameters.
Install
composer require marmarait/laraveldynamicsort
Optionally you can also add the jQuery Plugin provided to do the frontend part.
php artisan vendor:publish --provider=MarmaraIT\LaravelDynamicSort\DynamicallySortableProvider
Somewhere in the part of your layout add
@include('laraveldynamicsort::short_sort')
- If you are using gulp simply add "dynamicallySortable.js" to your gulpfile.js
- If you are using laravel-mix add "resources/assets/js/dynamicallySortable.js" to your webpack.mix
Usage
Backend:
- add the Trait "DynamicallySortable" to your model
- use the scope "ordered" on the model to sort it by querystring:
- add sort=COLUMNAME&dir=[[asc/desc]] to your query string to sort the active model
To use the jquery-plugin, give the table header(th) elements the attribute data-sort="COLUMNAME" and call the plugin $('.selector').dynamicallySortable() (selector = the th elements; f.e. $('th[data-sort]') )
Defaults
Set the defaultDir property on your model to define the default order direction (asc/desc)
Set the defaultSort property to set the default sorting column