'
);
}
}
],
order: [2, 'desc'], //set any columns order asc/desc
dom:
'<"card-header d-flex rounded-0 flex-wrap pb-md-0 pt-0"' +
'<"me-5 ms-n2"f>' +
'<"d-flex justify-content-start justify-content-md-end align-items-baseline"<"dt-action-buttons d-flex align-items-start align-items-md-center justify-content-sm-center mb-0 gap-4"lB>>' +
'>t' +
'<"row mx-1"' +
'<"col-sm-12 col-md-6"i>' +
'<"col-sm-12 col-md-6"p>' +
'>',
lengthMenu: [7, 10, 20, 50, 70, 100], //for length of menu
language: {
sLengthMenu: '_MENU_',
search: '',
searchPlaceholder: 'Search Category'
},
// Button for offcanvas
buttons: [
{
extend: 'collection',
className: 'btn btn-outline-secondary dropdown-toggle me-4 waves-effect waves-light',
text: ' Export',
buttons: [
{
extend: 'print',
text: 'Print',
className: 'dropdown-item',
exportOptions: {
columns: [1, 2, 3, 4, 5],
// prevent avatar to be print
format: {
body: function (inner, coldex, rowdex) {
if (inner.length <= 0) return inner;
var el = $.parseHTML(inner);
var result = '';
$.each(el, function (index, item) {
if (item.classList !== undefined && item.classList.contains('user-name')) {
result = result + item.lastChild.firstChild.textContent;
} else if (item.innerText === undefined) {
result = result + item.textContent;
} else result = result + item.innerText;
});
return result;
}
}
},
customize: function (win) {
//customize print view for dark
$(win.document.body)
.css('color', headingColor)
.css('border-color', borderColor)
.css('background-color', bodyBg);
$(win.document.body)
.find('table')
.addClass('compact')
.css('color', 'inherit')
.css('border-color', 'inherit')
.css('background-color', 'inherit');
}
},
{
extend: 'csv',
text: 'Csv',
className: 'dropdown-item',
exportOptions: {
columns: [1, 2, 3, 4, 5],
// prevent avatar to be display
format: {
body: function (inner, coldex, rowdex) {
if (inner.length <= 0) return inner;
var el = $.parseHTML(inner);
var result = '';
$.each(el, function (index, item) {
if (item.classList !== undefined && item.classList.contains('user-name')) {
result = result + item.lastChild.firstChild.textContent;
} else if (item.innerText === undefined) {
result = result + item.textContent;
} else result = result + item.innerText;
});
return result;
}
}
}
},
{
extend: 'excel',
text: 'Excel',
className: 'dropdown-item',
exportOptions: {
columns: [1, 2, 3, 4, 5],
// prevent avatar to be display
format: {
body: function (inner, coldex, rowdex) {
if (inner.length <= 0) return inner;
var el = $.parseHTML(inner);
var result = '';
$.each(el, function (index, item) {
if (item.classList !== undefined && item.classList.contains('user-name')) {
result = result + item.lastChild.firstChild.textContent;
} else if (item.innerText === undefined) {
result = result + item.textContent;
} else result = result + item.innerText;
});
return result;
}
}
}
},
{
extend: 'pdf',
text: 'Pdf',
className: 'dropdown-item',
exportOptions: {
columns: [1, 2, 3, 4, 5],
// prevent avatar to be display
format: {
body: function (inner, coldex, rowdex) {
if (inner.length <= 0) return inner;
var el = $.parseHTML(inner);
var result = '';
$.each(el, function (index, item) {
if (item.classList !== undefined && item.classList.contains('user-name')) {
result = result + item.lastChild.firstChild.textContent;
} else if (item.innerText === undefined) {
result = result + item.textContent;
} else result = result + item.innerText;
});
return result;
}
}
}
},
{
extend: 'copy',
text: 'Copy',
className: 'dropdown-item',
exportOptions: {
columns: [1, 2, 3, 4, 5],
// prevent avatar to be display
format: {
body: function (inner, coldex, rowdex) {
if (inner.length <= 0) return inner;
var el = $.parseHTML(inner);
var result = '';
$.each(el, function (index, item) {
if (item.classList !== undefined && item.classList.contains('user-name')) {
result = result + item.lastChild.firstChild.textContent;
} else if (item.innerText === undefined) {
result = result + item.textContent;
} else result = result + item.innerText;
});
return result;
}
}
}
}
]
},
{
text: 'Add Category',
className: 'add-new btn btn-primary waves-effect waves-light',
attr: {
'data-bs-toggle': 'offcanvas',
'data-bs-target': '#offcanvasEcommerceCategoryList'
}
}
],
// For responsive popup
responsive: {
details: {
display: $.fn.dataTable.Responsive.display.modal({
header: function (row) {
var data = row.data();
return 'Details of ' + data['categories'];
}
}),
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;
}
}
}
});
$('.dataTables_length').addClass('my-0');
$('.dt-action-buttons').addClass('pt-0');
}
});
//For form validation
(function () {
const eCommerceCategoryListForm = document.getElementById('eCommerceCategoryListForm');
//Add New customer Form Validation
const fv = FormValidation.formValidation(eCommerceCategoryListForm, {
fields: {
categoryTitle: {
validators: {
notEmpty: {
message: 'Please enter category title'
}
}
},
slug: {
validators: {
notEmpty: {
message: 'Please enter slug'
}
}
}
},
plugins: {
trigger: new FormValidation.plugins.Trigger(),
bootstrap5: new FormValidation.plugins.Bootstrap5({
// Use this for enabling/changing valid/invalid class
eleValidClass: 'is-valid',
rowSelector: function (field, ele) {
// field is the field name & ele is the field element
return '.mb-5';
}
}),
submitButton: new FormValidation.plugins.SubmitButton(),
// Submit the form when all fields are valid
// defaultSubmit: new FormValidation.plugins.DefaultSubmit(),
autoFocus: new FormValidation.plugins.AutoFocus()
}
});
})();