/* ------------------------------------------------------------------------------
*
* # Basic datatables
*
* Demo JS code for datatable_basic.html page
*
* ---------------------------------------------------------------------------- */
// Setup module
// ------------------------------
var DatatableBasic = function() {
//
// Setup module components
//
// Basic Datatable examples
var _componentDatatableBasic = function() {
if (!$().DataTable) {
console.warn('Warning - datatables.min.js is not loaded.');
return;
}
// Setting datatable defaults
$.extend( $.fn.dataTable.defaults, {
autoWidth: false,
responsive: true,
columnDefs: [{
orderable: false,
width: 100
}],
dom: '<"datatable-header"fl><"datatable-scroll"t><"datatable-footer"ip>',
language: {
search: 'Filter: _INPUT_',
searchPlaceholder: 'Type to filter...',
lengthMenu: 'Show: _MENU_',
paginate: { 'first': 'First', 'last': 'Last', 'next': $('html').attr('dir') == 'rtl' ? '←' : '→', 'previous': $('html').attr('dir') == 'rtl' ? '→' : '←' }
}
});
// Basic datatable
$('.datatable-basic').DataTable();
// Alternative pagination
$('.datatable-pagination').DataTable({
pagingType: "simple",
language: {
paginate: {'next': $('html').attr('dir') == 'rtl' ? 'Next ←' : 'Next →', 'previous': $('html').attr('dir') == 'rtl' ? '→ Prev' : '← Prev'}
}
});
// Datatable with saving state
$('.datatable-save-state').DataTable({
stateSave: true
});
// Scrollable datatable
var table = $('.datatable-scroll-y').DataTable({
autoWidth: true,
scrollY: 300
});
// Resize scrollable table when sidebar width changes
$('.sidebar-control').on('click', function() {
table.columns.adjust().draw();
});
};
// Select2 for length menu styling
var _componentSelect2 = function() {
if (!$().select2) {
console.warn('Warning - select2.min.js is not loaded.');
return;
}
// Initialize
$('.dataTables_length select').select2({
minimumResultsForSearch: Infinity,
dropdownAutoWidth: true,
width: 'auto'
});
};
//
// Return objects assigned to module
//
return {
init: function() {
_componentDatatableBasic();
_componentSelect2();
}
}
}();
// Initialize module
// ------------------------------
document.addEventListener('DOMContentLoaded', function() {
DatatableBasic.init();
});