Laravel datatable wrapper with Vue JS and Tailwind CSS.
Install using package manager:
npm install laravel-vue-datatables
Then add it to your component files
<!-- MyComponent.vue -->
<template>
<laravel-vue-datatables
route="https:://mydomain.com/table"
v-model:columns="columns"
/>
<!-- for Vue 2 component
<laravel-vue-datatables
route="https:://mydomain.com/table"
:columns.sync="columns"
/>
-->
</template>
<script>
import LaravelVueDatatables from 'laravel-vue-datatables';
require('laravel-vue-datatables/dist/laravel-vue-datatables.css');
export default {
name: 'MyComponent',
components: {
LaravelVueDatatables,
},
data() {
return {
columns: [
{
uniqid: 'firstName',
label: 'Full Name',
field: 'first_name',
visible: true,
sortable: true,
sortOrder: 'asc',
align: 'center',
format: (val, row) => `${val} ${row.last_name}`,
classes: 'py-2 font-bold text-blue-600',
headerClass: 'py-4',
},
...
]
}
}
...
}
</script>
Name | Type | Mandatory | Description |
---|---|---|---|
columns | Array | Yes |
Please refer to |
checked | Array | Optional |
Your v-model to get selected row if you use |
loading | Boolean | Optional |
Get loading state from datatable |
Name | Type | Mandatory | Default Value | Description |
---|---|---|---|---|
route | String | Yes | Enter your laravel uri for laravel-vue-datatables to get data from. | |
query | [ String, Array, Object ] | Optional |
|
Add your custom query parameters before get data from your laravel server.
Example as string:
Example as array:
Example as object:
|
title | String | Optional |
Generate table title. Note: This props will be rendered above search field, if you want to add above the table use |
|
caption | String | Optional |
Generate table caption with |
|
table-class | [ String, Array, Object ] | Optional |
|
Example as string:
Example as array:
Example as object:
|
table-style | [ String, Array, Object ] | Optional |
Example as string:
Example as array:
Example as object:
|
|
thead-class | [ String, Array, Object ] | Optional |
|
Example as string:
Example as array:
Example as object:
|
thead-style | [ String, Array, Object ] | Optional |
Example as string:
Example as array:
Example as object:
|
|
hoverable | Boolean | Optional |
|
Table row hover |
hover-class | [ String, Array, Object ] | Optional |
|
Example as String
Example as Array
Example as Object
Note: If you use tailwind css please use |
disable-loader | Boolean | Optional |
|
Disable table loading message |
loader-type | String | Optional |
|
Accept
|
loading-bar-class | [ String, Array, Object ] | Optional |
|
Example as String:
Example as Array:
Example as Object:
|
loading-bar-style | [ String, Array, Object ] | Optional |
Example as String:
Example as Array:
Example as Object:
|
|
disable-skeleton-loader | Boolean | Optional |
|
Disable skeleton loader on loading state |
no-data-label | String | Optional |
|
No data label text | no-result-label | String | Optional |
|
No result text |
Name | Type | Mandatory | Default Value | Description |
---|---|---|---|---|
with-select | String | Optional |
|
Show checkbox on first column of your datatable |
selected-key | String | Optional |
|
Datatable selected field.
Note: Make sure this field is inside first level of your object otherwise it will return false. |
checkbox-class | [ String, Array, Object ] | Optional |
|
Example as String:
Example as Array:
Example as Object:
|
checkbox-style | [ String, Array, Object ] | Optional |
Example as String:
Example as Array:
Example as Object:
|
Name | Type | Mandatory | Default Value | Description |
---|---|---|---|---|
grid | String | Optional |
|
Accepted value:
|
grid-container-class | [ String, Array, Object ] | Optional |
|
Example as String:
Example as Array:
Example as Object:
|
grid-container-style | [ String, Array, Object ] | Optional |
Example as String:
Example as Array:
Example as Object:
|
|
grid-row-count | [ Number, String ] | Optional |
|
Numbers of grid column in grid view |
Name | Type | Mandatory | Default Value | Description |
---|---|---|---|---|
disable-search | Boolean | Optional |
|
Disable search input field |
search-label | String | Optional |
|
search input field placeholder |
search-class | [ String, Array, Object ] | Optional |
|
Example as String:
Example as Array:
Example as Object:
|
search-style | [ String, Array, Object ] | Optional |
Example as String:
Example as Array:
Example as Object:
|
Name | Type | Mandatory | Default Value | Description |
---|---|---|---|---|
disable-reload-button | Boolean | Optional |
|
Disable reload button |
reload-button-label | String | Optional |
|
Reload button text |
reload-button-class | [ String, Array, Object ] | Optional |
|
Example as String:
Example as Array:
Example as Object:
|
reload-button-style | [ String, Array, Object ] | Optional |
Example as String:
Example as Array:
Example as Object:
|
Name | Type | Mandatory | Default Value | Description |
---|---|---|---|---|
reverse-head | Boolean | Optional |
|
Switch position on search field and reload button container. |
reverse-navigation | Boolean | Optional |
|
Switch position on pagination label and navigation buttons container. |
Name | Type | Mandatory | Default Value | Description |
---|---|---|---|---|
disable-pagination | Boolean | Optional |
|
Disable pagination label, rows per page and navigation buttons |
disable-pagination-label | Boolean | Optional |
|
Disable pagination label |
disable-navigation | Boolean | Optional |
|
Disable navigation buttons |
disable-goto-page | Boolean | Optional |
|
Disable go to page in navigation buttons |
goto-page-class | [ String, Array, Object ] | Optional |
|
Example as String:
Example as Array:
Example as Object:
|
goto-page-style | [ String, Array, Object ] | Optional |
Example as String:
Example as Array:
Example as Object:
|
|
rows-per-page-label | String | Optional |
|
Rows per page label |
rows-per-page | [ Number, String ] | Optional |
|
Numbers of rows for each page |
disable-rows-per-page | [ Boolean ] | Optional |
|
Disable row per page options |
rows-per-page-class | [ String, Array, Object ] | Optional |
|
Example as String:
Example as Array:
Example as Object:
|
rows-per-page-style | [ String, Array, Object ] | Optional |
Example as String:
Example as Array:
Example as Object:
|
|
rows-per-page-options | Array | Optional |
|
Rows per page options |
disable-first-page-button | Boolean | Optional |
|
Disable first page button in navigation buttons |
first-page-button-class | [ String, Array, Object ] | Optional |
|
Example as String:
Example as Array:
Example as Object:
|
first-page-button-style | [ String, Array, Object ] | Optional |
Example as String:
Example as Array:
Example as Object:
|
|
disable-last-page-button | Boolean | Optional |
|
Disable last page button in navigation buttons |
last-page-button-class | [ String, Array, Object ] | Optional |
|
Example as String:
Example as Array:
Example as Object:
|
last-page-button-style | [ String, Array, Object ] | Optional |
Example as String:
Example as Array:
Example as Object:
|
|
disable-previous-page-button | Boolean | Optional |
|
Disable previous page button in navigation buttons |
previous-page-button-class | [ String, Array, Object ] | Optional |
|
Example as String:
Example as Array:
Example as Object:
|
previous-page-button-style | [ String, Array, Object ] | Optional |
Example as String:
Example as Array:
Example as Object:
|
|
disable-next-page-button | Boolean | Optional |
|
Disable next page button in navigation buttons |
next-page-button-class | [ String, Array, Object ] | Optional |
|
Example as String:
Example as Array:
Example as Object:
|
next-page-button-style | [ String, Array, Object ] | Optional |
Example as String:
Example as Array:
Example as Object:
|
This props used to render columns and basic formating value, you can modified inside columns
export default {
...
data() {
return {
columns: [
{
uniqid: 'username',
label: 'Username',
field: 'username', // or use (row) => row.user.username
visible: true,
sortable: true,
sortOrder: 'asc',
align: 'center',
format: (val, row) => `Username: ${val}`
headerClass: 'py-4',
classes: [
'py-2',
'font-bold',
'text-blue-600'
],
},
{
uniqid: 'fullName',
label: 'Full Name',
field: 'firstName',
format: (val, row) => `${val} ${row.lastName}`
headerClass: {
'py-4': true
},
},
...
]
}
}
}
Name | Type | Mandatory | Default Value | Description |
---|---|---|---|---|
uniqid | String | Yes | Table header, cell and grid unique identifier. This props will used for naming slot for each header, cell and grid. |
|
label | String | Yes | Label for header column | |
field | [ String, Function ] | Optional |
|
Row Object property to determine value for this column or function which maps to the required property.
|
visible | Boolean | Optional |
|
This props will make column visible or not |
sortable | String | Optional |
|
Make this column sortable and to data query sent to your server |
sort-order | String | Optional |
|
Sort column sort order. |
align | Boolean | Optional |
|
Horizontal alignment of cells in this column. |
format | Function | Optional |
|
Function to format your data. Accept two arguments `val` and `row`. `val` contain value from `row` based on field props. |
header-class | [ String, Array, Object ] | Optional |
Class for Example as String:
Example as Array:
Example as Object:
|
|
header-style | [ String, Array, Object ] | Optional |
Style for Example as String:
Example as Array:
Example as Object:
|
|
classes | [ String, Array, Object ] | Optional |
Class for Example as String:
Example as Array:
Example as Object:
|
|
styles | [ String, Array, Object ] | Optional |
Style for Example as String:
Example as Array:
Example as Object:
|
#title |
Title of your table |
|
#before.data-table |
Used to add content before the table |
|
#after.data-table |
Used to add content after the table |
|
#before.search |
Used if you want to add content left of search field on tablet and desktop and top of search field on mobile |
|
#icon.search |
Slot for search field icon |
|
#after.search |
Used if you want to add content right of search field on tablet and desktop and bottom of search field on mobile |
|
#before.reload-button |
Used if you want to add content left of reload button on tablet and desktop and top of reload button on mobile |
|
#label.reload-button |
Slot to customize label reload button |
|
#after.reload-button |
Used if you want to add content right of reload button on tablet and desktop and bottom of reload button on mobile |
|
#label.no-record |
Used to customize text when no data found in table |
|
#label.no-result |
Used to render no result label |
|
#loader |
Used to customize loader inside table |
|
#before.pagination-label |
Used if you want to add content left of pagination label on tablet and desktop and top of pagination label on mobile |
|
#label.pagination |
Used to show count of data in table.
|
|
#after.pagination-label |
Used if you want to add content right of pagination label on tablet and desktop and bottom of pagination label on mobile |
|
#before.navigation |
Used if you want to add content left of navigation button on tablet and desktop and top of navigation button on mobile |
|
#after.navigation |
Used if you want to add content right of navigation button on tablet and desktop and bottom of navigation button on mobile |
|
#label.rows-per-page |
Used to customize text data per page. |
|
#icon.navigation.first-page-button |
Used to customize icon inside first page navigation button |
|
#icon.navigation.previous-page-button |
Used to customize icon inside previous page navigation button |
|
#icon.navigation.next-page-button |
Used to customize icon inside next page navigation button |
|
#icon.navigation.last-page-button |
Used to customize icon inside last page navigation button |
|
#footer |
Footer content of your table |
|
#icon.ascending |
Used to customize icon for ascending icon if you used sortable |
|
#icon.descending |
Used to customize icon for descending icon if you used sortable |
|
#table.row.prepend |
Used to prepend data in each rows of table |
|
#table.row.append |
Used to append data in each rows of table |
|
#table.row.skeleton |
Used to render skeleton loader per rows of table |
|
#table.cell.skeleton.checkbox |
Used to render skeleton loader checkbox in cell of table |
|
#grid.content.header.checkbox |
Used to customize checkbox label inside grid header |
|
#grid.prepend |
Used to prepend content in grid view |
|
#grid.append |
Used to append content in grid view |
|
#grid.skeleton.container |
Used to render skeleton loader at container grid view |
|
#grid.skeleton.body.checkbox |
Used to render skeleton loader at checkbox grid view |
|
#table.cell.header.[uniqid] |
Used to customize label in table header for spesific cell identified by
|
|
#table.cell.content.checkbox |
Used to customize checkbox for checkbox column. This slot has 1 arguments:
|
|
#table.cell.content.[uniqid] |
Used to customize cell value in table cell for spesific cell identified by
This slot has 2 arguments:
|
|
#grid.content.header.[uniqid] |
Used to customize label for spesific header identified by
|
|
#grid.content.body.checkbox |
Used to customize checkbox for checkbox line. This slot has 1 arguments:
|
|
#grid.content.body.[uniqid] |
Used to customize grid value for spesific row identified by
This slot has 2 arguments:
|
|
#table.cell.skeleton.[col.uniqid] |
Used to render skeleton loader for spesific column identified by
|
|
#grid.skeleton.body.[col.uniqid] |
Used to render skeleton loader for spesific grid column identified by
|
|
Example sent request to your server:
[
"search" => NULL,
"page" => "1",
"per_page" => "10",
"sortOrder" => [
[
"column" => "first_name",
"order" => "asc",
],
[
"column" => "email",
"order" => "desc",
],
],
]
If you add :query='[ "foo=bar", "hello=world" ]'
to your query props, it will send
[
"search" => NULL,
"page" => "1",
"per_page" => "10",
"sortOrder" => [
[
"column" => "carlicense",
"order" => "asc",
],
[
"column" => "terid",
"order" => "asc",
],
],
"foo" => "bar",
"hello" => "world",
]
Expected Response example from your server:
{
"current_page": 1,
"data": [
{
"id": 1,
"first_name": "John",
"last_name": "Doe",
"email": "[email protected]",
"phone": "00990025196",
"created_at": "2021-06-25 08:37:09",
"updated_at": "2021-06-25 08:37:09",
"isSelected": true,
...
},
...
],
"first_page_url": "http://example.com/table?page=1",
"from": 1,
"last_page": 17,
"last_page_url": "http://example.com/table?page=17",
"next_page_url": "http://example.com/table?page=2",
"path": "http://example.com/table",
"per_page": 10,
"prev_page_url": null,
"to": 10,
"total": 163
}
Notes!!
You may use the withQueryString
method if you would like to append all of the current request's query string values to the pagination links.
$users = User::paginate($request->input('per_page'))->withQueryString();