Download the PHP package distilleries/datatable-builder without Composer
On this page you can find all versions of the php package distilleries/datatable-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download distilleries/datatable-builder
More information about distilleries/datatable-builder
Files in distilleries/datatable-builder
Package datatable-builder
Short Description Based on https://github.com/chumper/datatable. It's an abstract class to implement the datatable like https://github.com/Distilleries/FormBuilder.
License MIT
Informations about the package datatable-builder
Laravel 5 Datatable Builder
Based on chumper/datatable. It's an abstract class to implement the datatable like the form generator.
Table of contents
- Installation
- Basic usage
- Closure
- BaseQuery
- Filters
- Styles
- Controller
Installation
Add on your composer.json
run composer update
.
Add Service provider to config/app.php
:
And Facade (also in config/app.php
)
Add the javascript on your bower dependencies:
Export the configuration:
Export the views (optional):
Export the Javascript assets (optional):
Include the javascript with gulp or grunt vendor/distilleries/datatable-builder/resources/**/*
.
If you don't use a task manager or you want override the javascript just publish those with the command line:
You can find those in resources/assets/vendor/datatable-builder
.
Basic usage
Creating form classes is easy. With a simple artisan command I can create a datatable:
you create form class in path app/Datatables/PostDatatable.php
that looks like this:
You can add fields which you want when creating command like this:
And that will create a datatable in path app/Datatables/SongDatatable.php
with content:
The method add
have in param:
add($name, $closure = null, $translation = '', $orderable = true)
Param | Usage |
---|---|
name | Name of the column |
closure | Function with the model in parameter to return a template. By default null use the attribute of the model. |
translation | Translation of the column, by default empty use the column name |
orderable | Flag to handle column orderable state, by default true |
Closure
When you create a datatatable sometime the content need to be get from other table or stylize by a template like the actions buttons.
For example an address is link to a profile. To display the profile name on the datatable like the picture you can use the closure.
On my model Address
I have:
You can return a template if you want:
BaseQuery
You can override the base query for the datatable query.
By default it will send a fresh full Query: $this->model->newModelQuery();
Filters
You can use complex filter to filter your datatable. To do that I use the library FormBuilder. All the datatable have a plain form filter. If you had field on this form that display the filters.
For example we want all the user only online.
I create a choice field:
When the filters are submitted you can apply it with the method applyFilters
.
By default this method create a where with the name of the filter field if it's an attribute of the model.
If you want change this behaviour you can override it.
If you don't want create a global scope of your model you just want restrict the display for this datatable.
you can use applyFilters
to do that.
For example I want display only the customer of the application: The datable work on the user model.
Styles
You want stylize your row to put it on green, blue or red.
You can do that with setClassRow
. By default this method check the status attribute.
If the status exist and it is empty we add the danger class to display it in red.
Controller
You can use the trait Distilleries\DatatableBuilder\States\DatatableStateTrait
to add in your controller the default methods use with the datatable.
Example:
I created a controller app/Http/Controllers/DatatableController
:
I add the controller on the route file :
Like you can see I inject the model and the datatable on the constructor. On the welcome template I put:
That it you have your datatable from the user model.
All versions of datatable-builder with dependencies
illuminate/support Version 5.8.*
illuminate/view Version 5.8.*
illuminate/filesystem Version 5.8.*
distilleries/datatable Version 3.1.*
distilleries/form-builder Version 2.13.*