123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- /* ------------------------------------------------------------------------------
- *
- * # 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: '<span>Filter:</span> _INPUT_',
- searchPlaceholder: 'Type to filter...',
- lengthMenu: '<span>Show:</span> _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();
- });
|