Permalink
Browse files

Datatables - option to overide the default init display length

  • Loading branch information...
bpocallaghan committed Jul 7, 2017
1 parent 0dd94dc commit 6d15555f0ab2866b479e0d30bfcd5b8245b202ab
@@ -26,13 +26,16 @@ $(function ()
initActionDeleteClick();
});
function initDatatablesAjax(selector, url, columns)
function initDatatablesAjax(selector, url, columns, displayLength)
{
displayLength = (displayLength ? displayLength : 10);
return initDataTables(selector, {
ajax: url,
processing: true,
serverSide: true,
columns: columns,
iDisplayLength: (displayLength ? displayLength : 10),
aLengthMenu: [[displayLength, 25, 50, -1], [displayLength, 25, 50, "All"]]
});
}
@@ -4,18 +4,18 @@
$(function ()
{
// check if we need to get data from server
if ($('#tbl-list').attr('data-server') == 'true') {
if ($("{{ (isset($id)? $id: '#tbl-list') }}").attr('data-server') == 'true') {
var options = {!! json_encode($options) !!}; // convert php array to js array
@if(isset($action) && $action == true || isset($action) == false)
options.push({
options.push({
data: 'action',
name: 'action',
orderable: false,
searchable: false,
visible: true
}); // add actions column
@endif
var table = initDatatablesAjax("{{ (isset($id)? $id: '#tbl-list') }}", "{{ (isset($url)? $url: request()->url().'/datatable') }}", options); // init datatables
var table = initDatatablesAjax("{{ (isset($id)? $id: '#tbl-list') }}", "{{ (isset($url)? $url: request()->url().'/datatable') }}", options, "{{ (isset($displayLength)? $displayLength: 10) }}"); // init datatables
}
})
</script>

0 comments on commit 6d15555

Please sign in to comment.