/** * DataTables Extensions (jquery) */ 'use strict'; $(function () { var dt_scrollable_table = $('.dt-scrollableTable'), dt_fixedheader_table = $('.dt-fixedheader'), dt_fixedcolumns_table = $('.dt-fixedcolumns'), dt_select_table = $('.dt-select-table'); // Scrollable // -------------------------------------------------------------------- if (dt_scrollable_table.length) { var dt_scrollableTable = dt_scrollable_table.DataTable({ ajax: assetsPath + 'json/table-datatable.json', columns: [ { data: 'full_name' }, { data: 'post' }, { data: 'email' }, { data: 'city' }, { data: 'start_date' }, { data: 'salary' }, { data: 'age' }, { data: 'experience' }, { data: '' }, { data: '' } ], columnDefs: [ { // Label targets: -2, render: function (data, type, full, meta) { var $status_number = full['status']; var $status = { 1: { title: 'Current', class: 'bg-label-primary' }, 2: { title: 'Professional', class: ' bg-label-success' }, 3: { title: 'Rejected', class: ' bg-label-danger' }, 4: { title: 'Resigned', class: ' bg-label-warning' }, 5: { title: 'Applied', class: ' bg-label-info' } }; if (typeof $status[$status_number] === 'undefined') { return data; } return ( '' + $status[$status_number].title + '' ); } }, { // Actions targets: -1, title: 'Actions', searchable: false, orderable: false, render: function (data, type, full, meta) { return ( '
' + '' + '' + '
' + '' ); } } ], // Scroll options scrollY: '300px', scrollX: true, dom: '<"row"<"col-sm-12 col-md-6"l><"col-sm-12 col-md-6 d-flex justify-content-center justify-content-md-end"f>>t<"row"<"col-sm-12 col-md-6"i><"col-sm-12 col-md-6"p>>' }); } // FixedHeader // -------------------------------------------------------------------- if (dt_fixedheader_table.length) { var dt_fixedheader = dt_fixedheader_table.DataTable({ ajax: assetsPath + 'json/table-datatable.json', columns: [ { data: '' }, { data: 'id' }, { data: 'id' }, { data: 'full_name' }, { data: 'email' }, { data: 'start_date' }, { data: 'salary' }, { data: 'status' }, { data: '' } ], columnDefs: [ { className: 'control', orderable: false, targets: 0, responsivePriority: 3, render: function (data, type, full, meta) { return ''; } }, { // For Checkboxes targets: 1, orderable: false, render: function () { return ''; }, checkboxes: { selectAllRender: '' }, responsivePriority: 4 }, { targets: 2, visible: false }, { // Avatar image/badge, Name and post targets: 3, render: function (data, type, full, meta) { var $user_img = full['avatar'], $name = full['full_name'], $post = full['post']; if ($user_img) { // For Avatar image var $output = 'Avatar'; } else { // For Avatar badge var stateNum = Math.floor(Math.random() * 6); var states = ['success', 'danger', 'warning', 'info', 'primary', 'secondary']; var $state = states[stateNum], $name = full['full_name']; var $initials = $name.match(/\b\w/g) || []; $initials = (($initials.shift() || '') + ($initials.pop() || '')).toUpperCase(); $output = '' + $initials + ''; } // Creates full output for row var $row_output = '
' + '
' + '
' + $output + '
' + '
' + '
' + '' + $name + '' + '' + $post + '' + '
' + '
'; return $row_output; }, responsivePriority: 5 }, { responsivePriority: 1, targets: 4 }, { responsivePriority: 2, targets: 6 }, { // Label targets: -2, render: function (data, type, full, meta) { // var $rand_num = Math.floor(Math.random() * 5) + 1; var $status_number = full['status']; var $status = { 1: { title: 'Current', class: 'bg-label-primary' }, 2: { title: 'Professional', class: ' bg-label-success' }, 3: { title: 'Rejected', class: ' bg-label-danger' }, 4: { title: 'Resigned', class: ' bg-label-warning' }, 5: { title: 'Applied', class: ' bg-label-info' } }; if (typeof $status[$status_number] === 'undefined') { return data; } return ( '' + $status[$status_number].title + '' ); } }, { // Actions targets: -1, title: 'Actions', orderable: false, render: function (data, type, full, meta) { return ( '
' + '' + '' + '
' + '' ); } } ], order: [[2, 'desc']], dom: '<"row"<"col-sm-12 col-md-6"l><"col-sm-12 col-md-6 d-flex justify-content-center justify-content-md-end"f>>t<"row"<"col-sm-12 col-md-6"i><"col-sm-12 col-md-6"p>>', displayLength: 7, lengthMenu: [7, 10, 25, 50, 75, 100], responsive: { details: { display: $.fn.dataTable.Responsive.display.modal({ header: function (row) { var data = row.data(); return 'Details of ' + data['full_name']; } }), type: 'column', renderer: function (api, rowIdx, columns) { var data = $.map(columns, function (col, i) { return col.title !== '' // ? Do not show row in modal popup if title is blank (for check box) ? '' + '' + col.title + ':' + ' ' + '' + col.data + '' + '' : ''; }).join(''); return data ? $('').append(data) : false; } } } }); // Fixed header if (window.Helpers.isNavbarFixed()) { var navHeight = $('#layout-navbar').outerHeight(); new $.fn.dataTable.FixedHeader(dt_fixedheader).headerOffset(navHeight); } else { new $.fn.dataTable.FixedHeader(dt_fixedheader); } } // FixedColumns // -------------------------------------------------------------------- if (dt_fixedcolumns_table.length) { var dt_fixedcolumns = dt_fixedcolumns_table.DataTable({ ajax: assetsPath + 'json/table-datatable.json', columns: [ { data: 'full_name' }, { data: 'post' }, { data: 'email' }, { data: 'city' }, { data: 'start_date' }, { data: 'salary' }, { data: 'age' }, { data: 'experience' }, { data: 'status' }, { data: 'id' } ], columnDefs: [ { // Label targets: -2, render: function (data, type, full, meta) { var $status_number = full['status']; var $status = { 1: { title: 'Current', class: 'bg-label-primary' }, 2: { title: 'Professional', class: ' bg-label-success' }, 3: { title: 'Rejected', class: ' bg-label-danger' }, 4: { title: 'Resigned', class: ' bg-label-warning' }, 5: { title: 'Applied', class: ' bg-label-info' } }; if (typeof $status[$status_number] === 'undefined') { return data; } return ( '' + $status[$status_number].title + '' ); } }, { // Actions targets: -1, title: 'Actions', searchable: false, orderable: false, render: function (data, type, full, meta) { return ( '
' + '' + '' + '
' + '' ); } } ], dom: '<"d-flex justify-content-between align-items-center row"<"col-sm-12 col-md-2 d-flex"f><"col-sm-12 col-md-10 d-none"i>>t', scrollY: 300, scrollX: true, scrollCollapse: true, paging: false, info: false, // Fixed column option fixedColumns: true }); } // Select // -------------------------------------------------------------------- if (dt_select_table.length) { var dt_select = dt_select_table.DataTable({ ajax: assetsPath + 'json/table-datatable.json', columns: [ { data: 'id' }, { data: 'full_name' }, { data: 'post' }, { data: 'email' }, { data: 'city' }, { data: 'start_date' }, { data: 'salary' }, { data: 'status' } ], columnDefs: [ { // For Checkboxes targets: 0, searchable: false, orderable: false, render: function () { return ''; }, checkboxes: { selectRow: true, selectAllRender: '' } }, { // Label targets: -1, render: function (data, type, full, meta) { var $status_number = full['status']; var $status = { 1: { title: 'Current', class: 'bg-label-primary' }, 2: { title: 'Professional', class: ' bg-label-success' }, 3: { title: 'Rejected', class: ' bg-label-danger' }, 4: { title: 'Resigned', class: ' bg-label-warning' }, 5: { title: 'Applied', class: ' bg-label-info' } }; if (typeof $status[$status_number] === 'undefined') { return data; } return ( '' + $status[$status_number].title + '' ); } } ], order: [[1, 'desc']], dom: '<"row"<"col-sm-12 col-md-6"l><"col-sm-12 col-md-6 d-flex justify-content-center justify-content-md-end"f>>t<"row"<"col-sm-12 col-md-6"i><"col-sm-12 col-md-6"p>>', select: { // Select style style: 'multi' } }); } // Filter form control to default size // ? setTimeout used for multilingual table initialization setTimeout(() => { $('.dataTables_filter .form-control').removeClass('form-control-sm'); $('.dataTables_length .form-select').removeClass('form-select-sm'); }, 200); });