# Options
Options are defined by using the setUp
method, E.g.:
use Sebastienheyd\Boilerplate\Datatables\Datatable;
class ExampleDatatable extends Datatable
{
public function setUp()
{
$this->permissions('users_crud')
->buttons('filters', 'csv', 'print')
->order('created_at', 'desc')
->pageLength(50)
->stateSave();
}
//...
}
option | default | description |
---|---|---|
order() | [] | Defines which column(s) the order is performed upon, and the ordering direction |
buttons() | ['filters'] | Shows buttons that will trigger some actions like showing filters, exporting to csv, ... |
condensed() | false | If called, the table will be condensed |
permissions() | ['backend_access'] | Sets the permissions to have to show the DataTable. |
stateSave | false | Restores table state on page reload |
showCheckboxes | false | Shows checkbox on each row |
lengthMenu() | [[10, 25, 50, 100, -1],[10,25,50,100,'∞']] | Specifies the entries in the length drop down |
pageLength() | 10 | Number of rows to display on a single page when using pagination |
pagingType() | simple_numbers | Type of buttons shown in the pagination control |
setRowId() | null | Sets id to rows |
setRowClass() | null | Sets class to rows |
setRowAttr() | null | Sets attribute(s) to rows |
noPaging() | visible | Disable paging |
noLengthChange() | visible | Disable length change |
noSorting() | visible | Disable sorting |
noOrdering() | visible | Disable sorting (alias) |
noSearching() | visible | Disable searching |
noInfo() | visible | Disable table informations |
locale() | [] | Set different locale for generic buttons |
# order
Single-column ordering as the initial state:
$this->order('id', 'desc')
Multi-column ordering as the initial state:
$this->order(['name' => 'desc', 'created_at' => 'desc'])
# buttons
Shows buttons that will trigger some actions. The arguments order is the order of appearance.
$this->buttons('filters', 'csv', 'refresh')
Built-in buttons : filters
, colvis
, csv
, excel
, copy
, print
, refresh
# condensed
If called, the table will be condensed.
$this->condensed()
# permissions
Sets the permissions to have to show the DataTable.
$this->permissions('users_crud', 'roles')
# stateSave
Enables state saving:
$this->stateSave()
# showCheckboxes
Shows checkbox on every row:
$this->showCheckboxes()
This will generate a checkbox on every row that can be used to select multiple elements.
To do this, every checkbox will be named dt-checkbox[]
and use the id as the key. E.g dt-checkbox[123]
.
But it's possible to set another field as the key by setting it when calling the method. E.g $this->showCheckboxes('item_id')
You can pass all the selected checkboxes to an ajax call by using the following selector :
$('input[name^=dt-checkbox]:checked').serialize()
# lengthMenu
Sets length menu options.
$this->lengthMenu([10,50,100])
To show options 10, 50, 100 and all records:
$this->lengthMenu([[10, 50, 100, -1] , [10, 50, 100, 'All']])
# pageLength
Shows 50 records per page:
$this->pageLength(50])
# pagingType
Sets numbers
as paging Type
->setPagingType('numbers')
Allowed types are
numbers
- Page number buttons onlysimple
- 'Previous' and 'Next' buttons onlysimple_numbers
- 'Previous' and 'Next' buttons, plus page numbersfull
- 'First', 'Previous', 'Next' and 'Last' buttonsfull_numbers
- 'First', 'Previous', 'Next' and 'Last' buttons, plus page numbersfirst_last_numbers
- 'First' and 'Last' buttons, plus page numbers
# setRowId
Sets row id via column
name.
->setRowId('id')
Sets row id via closure
.
->setRowId(function ($user) {
return $user->id;
})
Sets row id via blade
string.
->setRowId('{{$id}}')
# setRowClass
Sets row class via closure
.
->setRowClass(function ($user) {
return $user->id % 2 == 0 ? 'alert-success' : 'alert-warning';
})
# setRowAttr
Sets row attribute(s) via closure
.
->setRowAttr([
'data-id' => function($user) {
return 'row-' . $user->id;
},
'data-name' => function($user) {
return 'row-' . $user->name;
},
])
Sets row attribute(s) via blade
string.
->setRowAttr([
'data-id' => 'row-{{$id}}',
'data-name' => 'row-{{$name}}',
])
# noPaging
Disables paging:
$this->noPaging()
# noLengthChange
Disables length change:
$this->noLengthChange()
# noSorting
Disables sorting:
$this->noSorting()
# noOrdering
Disables sorting (alias):
$this->noOrdering()
# noSearching
Disables searching:
$this->noSearching()
# noInfo
Disables table informations:
$this->noInfo()
# locale
Sets different locale to use with generic buttons:
$this->locale([
'deleteConfirm' => 'Delete the article?',
'deleteSuccess' => 'Article has been successfully deleted',
])
Default locale can be found in the
datatable.php
(opens new window) lang file.
← Datasource Column →