/**
* App User View - Account (jquery)
*/
$(function () {
'use strict';
// Variable declaration for table
var dt_project_table = $('.datatable-project'),
dt_invoice_table = $('.datatable-invoice');
// Project datatable
// --------------------------------------------------------------------
if (dt_project_table.length) {
var dt_project = dt_project_table.DataTable({
ajax: assetsPath + 'json/user-profile.json',
columns: [
{ data: '' },
{ data: 'id' },
{ data: 'project_name' },
{ data: 'project_leader' },
{ data: '' },
{ data: 'status' },
{ data: '' }
],
columnDefs: [
{
// For Responsive
className: 'control',
searchable: false,
orderable: 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 '';
},
checkboxes: {
selectAllRender: ''
}
},
{
// Avatar image/badge, Name and post
targets: 2,
responsivePriority: 4,
render: function (data, type, full, meta) {
var $user_img = full['project_img'],
$name = full['project_name'],
$date = full['date'];
if ($user_img) {
// For Avatar image
var $output =
'
';
} 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['project_name'],
$initials = $name.match(/\b\w/g) || [];
$initials = (($initials.shift() || '') + ($initials.pop() || '')).toUpperCase();
$output = '' + $initials + '';
}
// Creates full output for row
var $row_output =
'
' +
'
' +
'
' +
$output +
'
' +
'
' +
'
' +
'' +
$name +
'' +
'' +
$date +
'' +
'
' +
'
';
return $row_output;
}
},
{
// Task
targets: 3,
render: function (data, type, full, meta) {
var $task = full['project_leader'];
return '' +
'
' +
'
' +
'
'
);
}
}
],
order: [[1, 'desc']],
dom:
'<"row mx-6"' +
'<"col-sm-6 col-12 d-flex align-items-center justify-content-center justify-content-sm-start mt-6 mt-sm-0"<"head-label">>' +
'<"col-sm-6 col-12 d-flex justify-content-center justify-content-md-end align-items-baseline"<"dt-action-buttons d-flex justify-content-center flex-md-row align-items-baseline gap-2"lB>>' +
'>t' +
'<"row mx-6"' +
'<"col-sm-12 col-xxl-6 text-center text-xxl-start pb-md-2 pb-xxl-0"i>' +
'<"col-sm-12 col-xxl-6 d-md-flex justify-content-xxl-end justify-content-center"p>' +
'>',
language: {
sLengthMenu: '_MENU_',
search: '',
searchPlaceholder: 'Search Invoice',
paginate: {
next: '
',
previous: '
'
}
},
// Buttons with Dropdown
buttons: [
{
extend: 'collection',
className: 'btn btn-label-secondary dropdown-toggle float-sm-end mb-3 mb-sm-0',
text: '
Export',
buttons: [
{
extend: 'print',
text: '
Print',
className: 'dropdown-item',
exportOptions: { columns: [1, 2, 3, 4] }
},
{
extend: 'csv',
text: '
Csv',
className: 'dropdown-item',
exportOptions: { columns: [1, 2, 3, 4] }
},
{
extend: 'excel',
text: '
Excel',
className: 'dropdown-item',
exportOptions: { columns: [1, 2, 3, 4] }
},
{
extend: 'pdf',
text: '
Pdf',
className: 'dropdown-item',
exportOptions: { columns: [1, 2, 3, 4] }
},
{
extend: 'copy',
text: '
Copy',
className: 'dropdown-item',
exportOptions: { columns: [1, 2, 3, 4] }
}
]
}
],
// For responsive popup
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;
}
}
}
});
$('div.head-label').html('
Invoice List
');
$('.dataTables_length .form-select').addClass('mx-0');
}
// On each datatable draw, initialize tooltip
dt_invoice_table.on('draw.dt', function () {
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl, {
boundary: document.body
});
});
});
// Delete Record
$('.datatable-invoice tbody').on('click', '.delete-record', function () {
dt_invoice.row($(this).parents('tr')).remove().draw();
});
// 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');
}, 300);
});