123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- /* ------------------------------------------------------------------------------
- *
- * # Responsive extension for Datatables
- *
- * Demo JS code for datatable_responsive.html page
- *
- * ---------------------------------------------------------------------------- */
- // Setup module
- // ------------------------------
- var DatatableResponsive = function() {
- //
- // Setup module components
- //
- // Basic Datatable examples
- var _componentDatatableResponsive = 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,
- targets: [ 5 ]
- }],
- dom: '<"datatable-header"fl><"datatable-scroll-wrap"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 responsive configuration
- $('.datatable-responsive').DataTable();
- // Column controlled child rows
- $('.datatable-responsive-column-controlled').DataTable({
- responsive: {
- details: {
- type: 'column'
- }
- },
- columnDefs: [
- {
- className: 'control',
- orderable: false,
- targets: 0
- },
- {
- width: "100px",
- targets: [6]
- },
- {
- orderable: false,
- targets: [6]
- }
- ],
- order: [1, 'asc']
- });
- // Control position
- $('.datatable-responsive-control-right').DataTable({
- responsive: {
- details: {
- type: 'column',
- target: -1
- }
- },
- columnDefs: [
- {
- className: 'control',
- orderable: false,
- targets: -1
- },
- {
- width: "100px",
- targets: [5]
- },
- {
- orderable: false,
- targets: [5]
- }
- ]
- });
- // Whole row as a control
- $('.datatable-responsive-row-control').DataTable({
- responsive: {
- details: {
- type: 'column',
- target: 'tr'
- }
- },
- columnDefs: [
- {
- className: 'control',
- orderable: false,
- targets: 0
- },
- {
- width: "100px",
- targets: [6]
- },
- {
- orderable: false,
- targets: [6]
- }
- ],
- order: [1, 'asc']
- });
- };
- // 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() {
- _componentDatatableResponsive();
- _componentSelect2();
- }
- }
- }();
- // Initialize module
- // ------------------------------
- document.addEventListener('DOMContentLoaded', function() {
- DatatableResponsive.init();
- });
|