| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086 |
- /**
- * DataTables Basic
- */
-
- 'use strict';
-
- let fv, offCanvasEl;
- document.addEventListener('DOMContentLoaded', function (e) {
- (function () {
- const formAddNewRecord = document.getElementById('form-add-new-record');
-
- setTimeout(() => {
- const newRecord = document.querySelector('.create-new'),
- offCanvasElement = document.querySelector('#add-new-record');
-
- // To open offCanvas, to add new record
- if (newRecord) {
- newRecord.addEventListener('click', function () {
- offCanvasEl = new bootstrap.Offcanvas(offCanvasElement);
- // Empty fields on offCanvas open
- (offCanvasElement.querySelector('.dt-full-name').value = ''),
- (offCanvasElement.querySelector('.dt-post').value = ''),
- (offCanvasElement.querySelector('.dt-email').value = ''),
- (offCanvasElement.querySelector('.dt-date').value = ''),
- (offCanvasElement.querySelector('.dt-salary').value = '');
- // Open offCanvas with form
- offCanvasEl.show();
- });
- }
- }, 200);
-
- // Form validation for Add new record
- fv = FormValidation.formValidation(formAddNewRecord, {
- fields: {
- basicFullname: {
- validators: {
- notEmpty: {
- message: 'The name is required'
- }
- }
- },
- basicPost: {
- validators: {
- notEmpty: {
- message: 'Post field is required'
- }
- }
- },
- basicEmail: {
- validators: {
- notEmpty: {
- message: 'The Email is required'
- },
- emailAddress: {
- message: 'The value is not a valid email address'
- }
- }
- },
- basicDate: {
- validators: {
- notEmpty: {
- message: 'Joining Date is required'
- },
- date: {
- format: 'MM/DD/YYYY',
- message: 'The value is not a valid date'
- }
- }
- },
- basicSalary: {
- validators: {
- notEmpty: {
- message: 'Basic Salary is required'
- }
- }
- }
- },
- plugins: {
- trigger: new FormValidation.plugins.Trigger(),
- bootstrap5: new FormValidation.plugins.Bootstrap5({
- // Use this for enabling/changing valid/invalid class
- // eleInvalidClass: '',
- eleValidClass: '',
- rowSelector: '.form-control-validation'
- }),
- submitButton: new FormValidation.plugins.SubmitButton(),
- // defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
- autoFocus: new FormValidation.plugins.AutoFocus()
- },
- init: instance => {
- instance.on('plugins.message.placed', function (e) {
- if (e.element.parentElement.classList.contains('input-group')) {
- e.element.parentElement.insertAdjacentElement('afterend', e.messageElement);
- }
- });
- }
- });
-
- // FlatPickr Initialization & Validation
- const flatpickrDate = document.querySelector('[name="basicDate"]');
-
- if (flatpickrDate) {
- flatpickrDate.flatpickr({
- enableTime: false,
- monthSelectorType: 'static',
- static: true,
- // See https://flatpickr.js.org/formatting/
- dateFormat: 'm/d/Y',
- // After selecting a date, we need to revalidate the field
- onChange: function () {
- fv.revalidateField('basicDate');
- }
- });
- }
- })();
-
- // init function
- const dt_basic_table = document.querySelector('.datatables-basic');
- let dt_basic;
-
- if (dt_basic_table) {
- let tableTitle = document.createElement('h5');
- tableTitle.classList.add('card-title', 'mb-0', 'text-md-start', 'text-center');
- tableTitle.innerHTML = 'DataTable with Buttons';
- dt_basic = new DataTable(dt_basic_table, {
- ajax: assetsPath + 'json/table-datatable.json',
- columns: [
- { data: 'id' },
- { data: 'id', orderable: false, render: DataTable.render.select() },
- { data: 'id' },
- { data: 'full_name' },
- { data: 'email' },
- { data: 'start_date' },
- { data: 'salary' },
- { data: 'status' },
- { data: 'id' }
- ],
- columnDefs: [
- {
- // For Responsive
- className: 'control',
- orderable: false,
- searchable: false,
- responsivePriority: 2,
- targets: 0,
- render: function (data, type, full, meta) {
- return '';
- }
- },
- {
- // For Checkboxes
- targets: 1,
- orderable: false,
- searchable: false,
- responsivePriority: 3,
- checkboxes: true,
- render: function () {
- return '<input type="checkbox" class="dt-checkboxes form-check-input">';
- },
- checkboxes: {
- selectAllRender: '<input type="checkbox" class="form-check-input">'
- }
- },
- {
- targets: 2,
- searchable: false,
- visible: false
- },
- {
- // Avatar image/badge, Name and post
- targets: 3,
- responsivePriority: 4,
- render: function (data, type, full, meta) {
- const userImg = full['avatar'];
- const name = full['full_name'];
- const post = full['post'];
- let output;
-
- if (userImg) {
- // For Avatar image
- output = `<img src="${assetsPath}img/avatars/${userImg}" alt="Avatar" class="rounded-circle">`;
- } else {
- // For Avatar badge
- const stateNum = Math.floor(Math.random() * 6);
- const states = ['success', 'danger', 'warning', 'info', 'dark', 'primary', 'secondary'];
- const state = states[stateNum];
- let initials = name.match(/\b\w/g) || [];
- initials = ((initials.shift() || '') + (initials.pop() || '')).toUpperCase();
- output = `<span class="avatar-initial rounded-circle bg-label-${state}">${initials}</span>`;
- }
-
- // Creates full output for row
- const rowOutput = `
- <div class="d-flex justify-content-start align-items-center user-name">
- <div class="avatar-wrapper">
- <div class="avatar me-2">
- ${output}
- </div>
- </div>
- <div class="d-flex flex-column">
- <span class="emp_name text-truncate text-heading">${name}</span>
- <small class="emp_post text-truncate">${post}</small>
- </div>
- </div>
- `;
-
- return rowOutput;
- }
- },
- {
- responsivePriority: 1,
- targets: 4
- },
- {
- // Label
- targets: -2,
- render: function (data, type, full, meta) {
- const statusNumber = full.status;
- const statuses = {
- 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 statuses[statusNumber] === 'undefined') {
- return data;
- }
-
- return `
- <span class="badge ${statuses[statusNumber].class}">
- ${statuses[statusNumber].title}
- </span>
- `;
- }
- },
- {
- // Actions
- targets: -1,
- title: 'Actions',
- orderable: false,
- searchable: false,
- className: 'd-flex align-items-center',
- render: function (data, type, full, meta) {
- return (
- '<div class="d-inline-block">' +
- '<a href="javascript:;" class="btn btn-icon dropdown-toggle hide-arrow" data-bs-toggle="dropdown"><i class="icon-base bx bx-dots-vertical-rounded"></i></a>' +
- '<ul class="dropdown-menu dropdown-menu-end m-0">' +
- '<li><a href="javascript:;" class="dropdown-item">Details</a></li>' +
- '<li><a href="javascript:;" class="dropdown-item">Archive</a></li>' +
- '<div class="dropdown-divider"></div>' +
- '<li><a href="javascript:;" class="dropdown-item text-danger delete-record">Delete</a></li>' +
- '</ul>' +
- '</div>' +
- '<a href="javascript:;" class="btn btn-icon item-edit"><i class="icon-base bx bx-edit icon-sm"></i></a>'
- );
- }
- }
- ],
- select: {
- style: 'multi',
- selector: 'td:nth-child(2)'
- },
- order: [[2, 'desc']],
- layout: {
- top2Start: {
- rowClass: 'row card-header flex-column flex-md-row pb-0',
- features: [tableTitle]
- },
- top2End: {
- features: [
- {
- buttons: [
- {
- extend: 'collection',
- className: 'btn btn-label-primary dropdown-toggle me-4',
- text: '<span class="d-flex align-items-center gap-2"><i class="icon-base bx bx-export me-sm-1"></i> <span class="d-none d-sm-inline-block">Export</span></span>',
- buttons: [
- {
- extend: 'print',
- text: `<span class="d-flex align-items-center"><i class="icon-base bx bx-printer me-1"></i>Print</span>`,
- className: 'dropdown-item',
- exportOptions: {
- columns: [3, 4, 5, 6, 7],
- format: {
- body: function (inner, coldex, rowdex) {
- if (inner.length <= 0) return inner;
-
- // Check if inner is HTML content
- if (inner.indexOf('<') > -1) {
- const parser = new DOMParser();
- const doc = parser.parseFromString(inner, 'text/html');
-
- // Get all text content
- let text = '';
-
- // Handle specific elements
- const userNameElements = doc.querySelectorAll('.user-name');
- if (userNameElements.length > 0) {
- userNameElements.forEach(el => {
- // Get text from nested structure
- const nameText =
- el.querySelector('.fw-medium')?.textContent ||
- el.querySelector('.d-block')?.textContent ||
- el.textContent;
- text += nameText.trim() + ' ';
- });
- } else {
- // Get regular text content
- text = doc.body.textContent || doc.body.innerText;
- }
-
- return text.trim();
- }
-
- return inner;
- }
- }
- },
- customize: function (win) {
- win.document.body.style.color = config.colors.headingColor;
- win.document.body.style.borderColor = config.colors.borderColor;
- win.document.body.style.backgroundColor = config.colors.bodyBg;
- const table = win.document.body.querySelector('table');
- table.classList.add('compact');
- table.style.color = 'inherit';
- table.style.borderColor = 'inherit';
- table.style.backgroundColor = 'inherit';
- }
- },
- {
- extend: 'csv',
- text: `<span class="d-flex align-items-center"><i class="icon-base bx bx-file me-1"></i>Csv</span>`,
- className: 'dropdown-item',
- exportOptions: {
- columns: [3, 4, 5, 6, 7],
- format: {
- body: function (inner, coldex, rowdex) {
- if (inner.length <= 0) return inner;
-
- // Parse HTML content
- const parser = new DOMParser();
- const doc = parser.parseFromString(inner, 'text/html');
-
- let text = '';
-
- // Handle user-name elements specifically
- const userNameElements = doc.querySelectorAll('.user-name');
- if (userNameElements.length > 0) {
- userNameElements.forEach(el => {
- // Get text from nested structure - try different selectors
- const nameText =
- el.querySelector('.fw-medium')?.textContent ||
- el.querySelector('.d-block')?.textContent ||
- el.textContent;
- text += nameText.trim() + ' ';
- });
- } else {
- // Handle other elements (status, role, etc)
- text = doc.body.textContent || doc.body.innerText;
- }
-
- return text.trim();
- }
- }
- }
- },
- {
- extend: 'excel',
- text: `<span class="d-flex align-items-center"><i class="icon-base bx bxs-file-export me-1"></i>Excel</span>`,
- className: 'dropdown-item',
- exportOptions: {
- columns: [3, 4, 5, 6, 7],
- format: {
- body: function (inner, coldex, rowdex) {
- if (inner.length <= 0) return inner;
-
- // Parse HTML content
- const parser = new DOMParser();
- const doc = parser.parseFromString(inner, 'text/html');
-
- let text = '';
-
- // Handle user-name elements specifically
- const userNameElements = doc.querySelectorAll('.user-name');
- if (userNameElements.length > 0) {
- userNameElements.forEach(el => {
- // Get text from nested structure - try different selectors
- const nameText =
- el.querySelector('.fw-medium')?.textContent ||
- el.querySelector('.d-block')?.textContent ||
- el.textContent;
- text += nameText.trim() + ' ';
- });
- } else {
- // Handle other elements (status, role, etc)
- text = doc.body.textContent || doc.body.innerText;
- }
-
- return text.trim();
- }
- }
- }
- },
- {
- extend: 'pdf',
- text: `<span class="d-flex align-items-center"><i class="icon-base bx bxs-file-pdf me-1"></i>Pdf</span>`,
- className: 'dropdown-item',
- exportOptions: {
- columns: [3, 4, 5, 6, 7],
- format: {
- body: function (inner, coldex, rowdex) {
- if (inner.length <= 0) return inner;
-
- // Parse HTML content
- const parser = new DOMParser();
- const doc = parser.parseFromString(inner, 'text/html');
-
- let text = '';
-
- // Handle user-name elements specifically
- const userNameElements = doc.querySelectorAll('.user-name');
- if (userNameElements.length > 0) {
- userNameElements.forEach(el => {
- // Get text from nested structure - try different selectors
- const nameText =
- el.querySelector('.fw-medium')?.textContent ||
- el.querySelector('.d-block')?.textContent ||
- el.textContent;
- text += nameText.trim() + ' ';
- });
- } else {
- // Handle other elements (status, role, etc)
- text = doc.body.textContent || doc.body.innerText;
- }
-
- return text.trim();
- }
- }
- }
- },
- {
- extend: 'copy',
- text: `<i class="icon-base bx bx-copy me-1"></i>Copy`,
- className: 'dropdown-item',
- exportOptions: {
- columns: [3, 4, 5, 6, 7],
- format: {
- body: function (inner, coldex, rowdex) {
- if (inner.length <= 0) return inner;
-
- // Parse HTML content
- const parser = new DOMParser();
- const doc = parser.parseFromString(inner, 'text/html');
-
- let text = '';
-
- // Handle user-name elements specifically
- const userNameElements = doc.querySelectorAll('.user-name');
- if (userNameElements.length > 0) {
- userNameElements.forEach(el => {
- // Get text from nested structure - try different selectors
- const nameText =
- el.querySelector('.fw-medium')?.textContent ||
- el.querySelector('.d-block')?.textContent ||
- el.textContent;
- text += nameText.trim() + ' ';
- });
- } else {
- // Handle other elements (status, role, etc)
- text = doc.body.textContent || doc.body.innerText;
- }
-
- return text.trim();
- }
- }
- }
- }
- ]
- },
- {
- text: '<span class="d-flex align-items-center gap-2"><i class="icon-base bx bx-plus icon-sm"></i> <span class="d-none d-sm-inline-block">Add New Record</span></span>',
- className: 'create-new btn btn-primary'
- }
- ]
- }
- ]
- },
- topStart: {
- rowClass: 'row m-3 my-0 justify-content-between',
- features: [
- {
- pageLength: {
- menu: [10, 25, 50, 100],
- text: 'Show_MENU_entries'
- }
- }
- ]
- },
- topEnd: {
- search: {
- placeholder: ''
- }
- },
- bottomStart: {
- rowClass: 'row mx-3 justify-content-between',
- features: ['info']
- },
- bottomEnd: 'paging'
- },
- language: {
- paginate: {
- next: '<i class="icon-base bx bx-chevron-right scaleX-n1-rtl icon-18px"></i>',
- previous: '<i class="icon-base bx bx-chevron-left scaleX-n1-rtl icon-18px"></i>',
- first: '<i class="icon-base bx bx-chevrons-left scaleX-n1-rtl icon-18px"></i>',
- last: '<i class="icon-base bx bx-chevrons-right scaleX-n1-rtl icon-18px"></i>'
- }
- },
- responsive: {
- details: {
- display: DataTable.Responsive.display.modal({
- header: function (row) {
- const data = row.data();
- return 'Details of ' + data['full_name'];
- }
- }),
- type: 'column',
- renderer: function (api, rowIdx, columns) {
- const data = columns
- .map(function (col) {
- return col.title !== '' // Do not show row in modal popup if title is blank (for check box)
- ? `<tr data-dt-row="${col.rowIndex}" data-dt-column="${col.columnIndex}">
- <td>${col.title}:</td>
- <td>${col.data}</td>
- </tr>`
- : '';
- })
- .join('');
-
- if (data) {
- const div = document.createElement('div');
- div.classList.add('table-responsive');
- const table = document.createElement('table');
- div.appendChild(table);
- table.classList.add('table');
- table.classList.add('datatables-basic');
- const tbody = document.createElement('tbody');
- tbody.innerHTML = data;
- table.appendChild(tbody);
- return div;
- }
- return false;
- }
- }
- }
- });
-
- // Add New record
- // ? Remove/Update this code as per your requirements
- var count = 101;
- // On form submit, if form is valid
- fv.on('core.form.valid', function () {
- let new_name = document.querySelector('.add-new-record .dt-full-name').value,
- new_post = document.querySelector('.add-new-record .dt-post').value,
- new_email = document.querySelector('.add-new-record .dt-email').value,
- new_date = document.querySelector('.add-new-record .dt-date').value,
- new_salary = document.querySelector('.add-new-record .dt-salary').value;
-
- if (new_name != '') {
- dt_basic.row
- .add({
- id: count,
- full_name: new_name,
- post: new_post,
- email: new_email,
- start_date: new_date,
- salary: '$' + new_salary,
- status: 5
- })
- .draw();
- count++;
-
- // Hide offcanvas using javascript method
- offCanvasEl.hide();
- }
- });
-
- //? The 'delete-record' class is necessary for the functionality of the following code.
- document.addEventListener('click', function (e) {
- if (e.target.classList.contains('delete-record')) {
- dt_basic.row(e.target.closest('tr')).remove().draw();
- const modalEl = document.querySelector('.dtr-bs-modal');
- if (modalEl && modalEl.classList.contains('show')) {
- const modal = bootstrap.Modal.getInstance(modalEl);
- modal?.hide();
- }
- }
- });
- }
-
- // Complex Header DataTable
-
- const dt_complex_header_table = document.querySelector('.dt-complex-header');
- let dt_complex;
-
- if (dt_complex_header_table) {
- dt_complex = new DataTable(dt_complex_header_table, {
- ajax: assetsPath + 'json/table-datatable.json',
- columns: [
- { data: 'full_name' },
- { data: 'email' },
- { data: 'city' },
- { data: 'post' },
- { data: 'salary' },
- { data: 'status' },
- { data: '' }
- ],
- columnDefs: [
- {
- // Label
- targets: -2,
- render: function (data, type, full, meta) {
- const statusNumber = full.status;
- const statuses = {
- 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 statuses[statusNumber] === 'undefined') {
- return data;
- }
-
- return `
- <span class="badge ${statuses[statusNumber].class}">
- ${statuses[statusNumber].title}
- </span>
- `;
- }
- },
- {
- // Actions
- targets: -1,
- title: 'Actions',
- orderable: false,
- searchable: false,
- render: function (data, type, full, meta) {
- return (
- '<div class="d-inline-block">' +
- '<a href="javascript:;" class="btn btn-icon dropdown-toggle hide-arrow" data-bs-toggle="dropdown"><i class="icon-base bx bx-dots-vertical-rounded"></i></a>' +
- '<ul class="dropdown-menu dropdown-menu-end m-0">' +
- '<li><a href="javascript:;" class="dropdown-item">Details</a></li>' +
- '<li><a href="javascript:;" class="dropdown-item">Archive</a></li>' +
- '<div class="dropdown-divider"></div>' +
- '<li><a href="javascript:;" class="dropdown-item text-danger delete-record">Delete</a></li>' +
- '</ul>' +
- '</div>' +
- '<a href="javascript:;" class="btn btn-icon item-edit"><i class="icon-base bx bx-edit icon-sm"></i></a>'
- );
- }
- }
- ],
- order: [[2, 'desc']],
- layout: {
- topStart: {
- rowClass: 'row mx-3 my-0 justify-content-between',
- features: [
- {
- pageLength: {
- menu: [7, 10, 25, 50, 100],
- text: 'Show_MENU_entries'
- }
- }
- ]
- },
- topEnd: {
- search: {
- placeholder: ''
- }
- },
- bottomStart: {
- rowClass: 'row mx-3 justify-content-between',
- features: ['info']
- },
- bottomEnd: 'paging'
- },
- displayLength: 7,
- language: {
- paginate: {
- next: '<i class="icon-base bx bx-chevron-right scaleX-n1-rtl icon-18px"></i>',
- previous: '<i class="icon-base bx bx-chevron-left scaleX-n1-rtl icon-18px"></i>',
- first: '<i class="icon-base bx bx-chevrons-left scaleX-n1-rtl icon-18px"></i>',
- last: '<i class="icon-base bx bx-chevrons-right scaleX-n1-rtl icon-18px"></i>'
- }
- }
- });
-
- //? The 'delete-record' class is necessary for the functionality of the following code.
- document.addEventListener('click', function (e) {
- if (e.target.classList.contains('delete-record')) {
- dt_complex.row(e.target.closest('tr')).remove().draw();
- const modalEl = document.querySelector('.dtr-bs-modal');
- if (modalEl && modalEl.classList.contains('show')) {
- const modal = bootstrap.Modal.getInstance(modalEl);
- modal?.hide();
- }
- }
- });
- }
-
- // Row Grouping DataTable
- const dt_row_grouping_table = document.querySelector('.dt-row-grouping');
- let dt_row_grouping,
- groupColumn = 2;
-
- if (dt_row_grouping_table) {
- dt_row_grouping = new DataTable(dt_row_grouping_table, {
- 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' },
- { data: '' }
- ],
- columnDefs: [
- {
- // For Responsive
- className: 'control',
- orderable: false,
- targets: 0,
- searchable: false,
- render: function (data, type, full, meta) {
- return '';
- }
- },
- { visible: false, targets: groupColumn },
- {
- // Label
- targets: -2,
- render: function (data, type, full, meta) {
- const statusNumber = full.status;
- const statuses = {
- 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 statuses[statusNumber] === 'undefined') {
- return data;
- }
-
- return `
- <span class="badge ${statuses[statusNumber].class}">
- ${statuses[statusNumber].title}
- </span>
- `;
- }
- },
- {
- // Actions
- targets: -1,
- title: 'Actions',
- orderable: false,
- searchable: false,
- className: 'd-flex align-items-center',
- render: function (data, type, full, meta) {
- return (
- '<div class="d-inline-block">' +
- '<a href="javascript:;" class="btn btn-icon dropdown-toggle hide-arrow me-1" data-bs-toggle="dropdown"><i class="bx bx-dots-vertical-rounded icon-base"></i></a>' +
- '<div class="dropdown-menu dropdown-menu-end m-0">' +
- '<a href="javascript:;" class="dropdown-item">Details</a>' +
- '<a href="javascript:;" class="dropdown-item">Archive</a>' +
- '<div class="dropdown-divider"></div>' +
- '<a href="javascript:;" class="dropdown-item text-danger delete-record">Delete</a>' +
- '</div>' +
- '</div>' +
- '<a href="javascript:;" class="btn btn-icon item-edit"><i class="icon-base bx bx-edit icon-sm"></i></a>'
- );
- }
- }
- ],
- layout: {
- topStart: {
- rowClass: 'row mx-3 my-0 justify-content-between',
- features: [
- {
- pageLength: {
- menu: [7, 10, 25, 50, 100],
- text: 'Show_MENU_entries'
- }
- }
- ]
- },
- topEnd: {
- search: {
- placeholder: ''
- }
- },
- bottomStart: {
- rowClass: 'row mx-3 justify-content-between',
- features: ['info']
- },
- bottomEnd: 'paging'
- },
- order: [[groupColumn, 'asc']],
- displayLength: 7,
- language: {
- paginate: {
- next: '<i class="icon-base bx bx-chevron-right scaleX-n1-rtl icon-18px"></i>',
- previous: '<i class="icon-base bx bx-chevron-left scaleX-n1-rtl icon-18px"></i>',
- first: '<i class="icon-base bx bx-chevrons-left scaleX-n1-rtl icon-18px"></i>',
- last: '<i class="icon-base bx bx-chevrons-right scaleX-n1-rtl icon-18px"></i>'
- }
- },
- drawCallback: function (settings) {
- const api = this.api();
- const rows = api.rows({ page: 'current' }).nodes();
- let last = null;
-
- api
- .column(groupColumn, { page: 'current' })
- .data()
- .each(function (group, i) {
- if (last !== group) {
- const newRow = document.createElement('tr');
- newRow.classList.add('group');
-
- const newCell = document.createElement('td');
- newCell.setAttribute('colspan', '8');
- newCell.textContent = group;
-
- newRow.appendChild(newCell);
-
- rows[i].parentNode.insertBefore(newRow, rows[i]);
- last = group;
- }
- });
- },
- responsive: {
- details: {
- display: DataTable.Responsive.display.modal({
- header: function (row) {
- var data = row.data();
- return 'Details of ' + data['full_name'];
- }
- }),
- type: 'column',
- renderer: function (api, rowIdx, columns) {
- const data = columns
- .map(function (col) {
- return col.title !== '' // Do not show row in modal popup if title is blank (for check box)
- ? `<tr data-dt-row="${col.rowIndex}" data-dt-column="${col.columnIndex}">
- <td>${col.title}:</td>
- <td>${col.data}</td>
- </tr>`
- : '';
- })
- .join('');
-
- if (data) {
- const div = document.createElement('div');
- div.classList.add('table-responsive');
- const table = document.createElement('table');
- div.appendChild(table);
- table.classList.add('table');
- const tbody = document.createElement('tbody');
- tbody.innerHTML = data;
- table.appendChild(tbody);
- return div;
- }
- return false;
- }
- }
- }
- });
- //? The 'delete-record' class is necessary for the functionality of the following code.
- document.addEventListener('click', function (e) {
- if (e.target.classList.contains('delete-record')) {
- dt_row_grouping.row(e.target.closest('tr')).remove().draw();
- const modalEl = document.querySelector('.dtr-bs-modal');
- if (modalEl && modalEl.classList.contains('show')) {
- const modal = bootstrap.Modal.getInstance(modalEl);
- modal?.hide();
- }
- }
- });
- }
-
- // Multilingual DataTable
- const dt_multilingual_table = document.querySelector('.dt-multilingual');
- let dt_multilingual,
- lang = 'DE';
-
- if (dt_multilingual_table) {
- dt_multilingual = new DataTable(dt_multilingual_table, {
- ajax: assetsPath + 'json/table-datatable.json',
- columns: [
- { data: 'id' },
- { data: 'full_name' },
- { data: 'post' },
- { data: 'email' },
- { data: 'start_date' },
- { data: 'salary' },
- { data: 'status' },
- { data: '' }
- ],
- columnDefs: [
- {
- // For Responsive
- className: 'control',
- orderable: false,
- targets: 0,
- searchable: false,
- render: function (data, type, full, meta) {
- return '';
- }
- },
- {
- // Label
- targets: -2,
- render: function (data, type, full, meta) {
- const statusNumber = full.status;
- const statuses = {
- 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 statuses[statusNumber] === 'undefined') {
- return data;
- }
-
- return `
- <span class="badge ${statuses[statusNumber].class}">
- ${statuses[statusNumber].title}
- </span>
- `;
- }
- },
- {
- // Actions
- targets: -1,
- title: 'Actions',
- orderable: false,
- className: '',
- searchable: false,
- render: function (data, type, full, meta) {
- return (
- '<div class="d-flex align-items-center">' +
- '<div class="d-inline-block">' +
- '<a href="javascript:;" class="btn btn-icon dropdown-toggle hide-arrow me-1" data-bs-toggle="dropdown"><i class="icon-base bx bx-dots-vertical-rounded icon-sm"></i></a>' +
- '<div class="dropdown-menu dropdown-menu-end m-0">' +
- '<a href="javascript:;" class="dropdown-item">Details</a>' +
- '<a href="javascript:;" class="dropdown-item">Archive</a>' +
- '<div class="dropdown-divider"></div>' +
- '<a href="javascript:;" class="dropdown-item text-danger delete-record">Delete</a>' +
- '</div>' +
- '</div>' +
- '<a href="javascript:;" class="btn btn-icon item-edit"><i class="icon-base bx bx-edit icon-sm"></i></a>' +
- '</div>'
- );
- }
- }
- ],
- language: {
- url: 'https://cdn.datatables.net/plug-ins/1.11.5/i18n/de-' + lang + '.json',
- paginate: {
- next: '<i class="icon-base bx bx-chevron-right scaleX-n1-rtl icon-sm"></i>',
- previous: '<i class="icon-base bx bx-chevron-left scaleX-n1-rtl icon-sm"></i>'
- }
- },
- order: [[2, 'desc']],
- displayLength: 7,
- layout: {
- topStart: {
- rowClass: 'row m-3 justify-content-between',
- features: [
- {
- pageLength: {
- menu: [7, 10, 25, 50, 100]
- }
- }
- ]
- },
- topEnd: {
- search: {
- placeholder: 'Geben Sie hier die Suche ein'
- }
- },
- bottomStart: {
- rowClass: 'row mx-3 justify-content-between',
- features: ['info']
- },
- bottomEnd: 'paging'
- },
- responsive: {
- details: {
- display: DataTable.Responsive.display.modal({
- header: function (row) {
- var data = row.data();
- return 'Details of ' + data['full_name'];
- }
- }),
- type: 'column',
- renderer: function (api, rowIdx, columns) {
- const data = columns
- .map(function (col) {
- return col.title !== '' // Do not show row in modal popup if title is blank (for check box)
- ? `<tr data-dt-row="${col.rowIndex}" data-dt-column="${col.columnIndex}">
- <td>${col.title}:</td>
- <td>${col.data}</td>
- </tr>`
- : '';
- })
- .join('');
-
- if (data) {
- const div = document.createElement('div');
- div.classList.add('table-responsive');
- const table = document.createElement('table');
- div.appendChild(table);
- table.classList.add('table');
- const tbody = document.createElement('tbody');
- tbody.innerHTML = data;
- table.appendChild(tbody);
- return div;
- }
- return false;
- }
- }
- }
- });
-
- //? The 'delete-record' class is necessary for the functionality of the following code.
- document.addEventListener('click', function (e) {
- if (e.target.classList.contains('delete-record')) {
- dt_multilingual.row(e.target.closest('tr')).remove().draw();
- const modalEl = document.querySelector('.dtr-bs-modal');
- if (modalEl && modalEl.classList.contains('show')) {
- const modal = bootstrap.Modal.getInstance(modalEl);
- modal?.hide();
- }
- }
- });
- }
-
- // Filter form control to default size
- // ? setTimeout used for multilingual table initialization
- setTimeout(() => {
- const elementsToModify = [
- { selector: '.dt-buttons .btn', classToRemove: 'btn-secondary' },
- { selector: '.dt-search .form-control', classToRemove: 'form-control-sm', classToAdd: 'ms-4' },
- { selector: '.dt-length .form-select', classToRemove: 'form-select-sm' },
- { selector: '.dt-layout-table', classToRemove: 'row mt-2' },
- { selector: '.dt-layout-end', classToAdd: 'mt-0' },
- { selector: '.dt-layout-end .dt-search', classToAdd: 'mt-0 mt-md-6' },
- { selector: '.dt-layout-start', classToAdd: 'mt-0' },
- { selector: '.dt-layout-end .dt-buttons', classToAdd: 'mb-0' },
- { selector: '.dt-layout-full', classToRemove: 'col-md col-12', classToAdd: 'table-responsive' }
- ];
-
- // Delete record
- elementsToModify.forEach(({ selector, classToRemove, classToAdd }) => {
- document.querySelectorAll(selector).forEach(element => {
- if (classToRemove) {
- classToRemove.split(' ').forEach(className => element.classList.remove(className));
- }
- if (classToAdd) {
- classToAdd.split(' ').forEach(className => element.classList.add(className));
- }
- });
- });
- }, 100);
- });
|