Laravel Vue Datatable
A Vue.js datatable component for Laravel that works with Bootstrap.
Requirements
- Vue.js 2.x
- Laravel 5.x
- Bootstrap 4 (Optional)
This package makes use of an optional default component, the Laravel Vue Pagination component created by gilbitron. If you need a pagination component for other areas of your website and you are using a Laravel API & Bootstrap, i highly suggest using this flexible component.
Package Installation
See details https://github.com/jamesdordoy/Laravel-Vue-Datatables
Component Installation
Register the Plugin
Basic Example
UserDatatable.vue
API
Datatable Props
Name | Type | Default | Description |
---|---|---|---|
url |
String | "/" | The JSON url |
columns |
Array | [] | The table columns |
per-page |
Array | [ '10', '25', '50' ] | (optional) Amount to be displayed |
classes |
Object | See Below | (optional) Table classes |
pagination |
Object | {} | (optional) props for gilbitron/laravel-vue-pagination |
Default Classes
Column Props
Name | Type | Default | Description |
---|---|---|---|
label |
String | "" | The JSON url |
name |
String | "" | The table column header name |
width |
Number | 0 | The table column width |
filterable |
Boolean | false | Is the column filterable |
component |
Component | null | A dynamic component that can be injected |
classes |
Object | {} | Component classes to parse |
Using Dynamic Components
You can also inject your own components into the table such as buttons. Your buttons, links etc can also listen for events.
Example Button Component
(ExampleButton.vue)
Dynamic Datatable Columns
(UserDatatable.vue)
Overriding the Filters and Pagination Components
If the included pagination or filters do not meet your requirements or if the styling is incorrect, they can be over-written using scoped slots.
Paginatior Datatable
Once the URL has been updated by your customer paginator or filters, the table will re-render. Alterativly, if updating the URL is troublesome, different table filters can be manipulated by your filters using the v-model directive:
Example Filter
(DatatableFilter.vue)
This example filter will control the length of the table manipulating the tableData.length property using v-model.
Filter Datatable
Custom Filters
You can also add your own custom filters to be sent to the Laravel backend:
Datatable
Example Filter
This added "isAdmin" filter for staff type will be send to the Laravel backend and can be used to manipulate the results:
Styling the Datatable
You can edit the style of the Datatable by overriding the classes
prop. A example mixin config can be found be below for Tailwind:
Tailwind Config
(mixins/tailwind.js)
Custom Class
Tailwind Datatable
Development
To work on the library locally, run the following command:
To run the tests: