Skip to content

Commit

Permalink
Datatables - option to overide the default init display length
Browse files Browse the repository at this point in the history
  • Loading branch information
bpocallaghan committed Jul 7, 2017
1 parent 0dd94dc commit 6d15555
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion resources/assets/admin/js/titan/datatables.js
Expand Up @@ -26,13 +26,16 @@ $(function ()
initActionDeleteClick(); initActionDeleteClick();
}); });


function initDatatablesAjax(selector, url, columns) function initDatatablesAjax(selector, url, columns, displayLength)
{ {
displayLength = (displayLength ? displayLength : 10);
return initDataTables(selector, { return initDataTables(selector, {
ajax: url, ajax: url,
processing: true, processing: true,
serverSide: true, serverSide: true,
columns: columns, columns: columns,
iDisplayLength: (displayLength ? displayLength : 10),
aLengthMenu: [[displayLength, 25, 50, -1], [displayLength, 25, 50, "All"]]
}); });
} }


Expand Down
6 changes: 3 additions & 3 deletions resources/views/admin/partials/datatables.blade.php
Expand Up @@ -4,18 +4,18 @@
$(function () $(function ()
{ {
// check if we need to get data from server // 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 var options = {!! json_encode($options) !!}; // convert php array to js array
@if(isset($action) && $action == true || isset($action) == false) @if(isset($action) && $action == true || isset($action) == false)
options.push({ options.push({
data: 'action', data: 'action',
name: 'action', name: 'action',
orderable: false, orderable: false,
searchable: false, searchable: false,
visible: true visible: true
}); // add actions column }); // add actions column
@endif @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> </script>
Expand Down

0 comments on commit 6d15555

Please sign in to comment.