|
|
@@ -62,14 +62,125 @@ export class CustomerComponent implements OnInit {
|
|
|
|
|
|
|
|
|
this.dtOptions = {
|
|
|
- paging: true,
|
|
|
+ // paging: true,
|
|
|
pagingType: 'full_numbers',
|
|
|
pageLength: 15,
|
|
|
processing: true,
|
|
|
order: [],
|
|
|
lengthMenu: [15, 25, 35],
|
|
|
- ordering: false,
|
|
|
+ ordering: true,
|
|
|
dom: 'Blfrtip',
|
|
|
+ initComplete: function(settings: any, json: any) {
|
|
|
+ const api = new $.fn.dataTable.Api(settings);
|
|
|
+
|
|
|
+ // Add filter row for spacing (optional)
|
|
|
+ const tableHeader = $(settings.nTable).find('thead');
|
|
|
+ if (!tableHeader.find('.filter-row').length) {
|
|
|
+ tableHeader.append('<tr class="filter-row"></tr>');
|
|
|
+ }
|
|
|
+ const filterRow = tableHeader.find('.filter-row');
|
|
|
+
|
|
|
+ api.columns().every(function () {
|
|
|
+ const column = this;
|
|
|
+ const colIndex = column.index();
|
|
|
+ const header = $(column.header());
|
|
|
+ const colName = header.text().trim(); // get column name text
|
|
|
+
|
|
|
+ // --- SORT BUTTON (always added) ---
|
|
|
+ // const sortBtn = $('<button class="sort-btn"></button>');
|
|
|
+ const sortBtn = $('<button class="sort-btn" style="margin-left:4px;border:none;background:none;cursor:pointer;font-size:12px;"></button>');
|
|
|
+
|
|
|
+ let sortState = 0;
|
|
|
+ sortBtn.on('click', function () {
|
|
|
+ // if (sortState === 0) { api.order([colIndex,'asc']).draw(); sortBtn.text('▲'); sortState = 1; }
|
|
|
+ // else if (sortState === 1) { api.order([colIndex,'desc']).draw(); sortBtn.text('▼'); sortState = 2; }
|
|
|
+ // else { api.order([]).draw(); sortBtn.text('⬍'); sortState = 0; }
|
|
|
+ });
|
|
|
+ header.append(sortBtn);
|
|
|
+
|
|
|
+ // --- Skip filter if column is in skip list ---
|
|
|
+ // if (skipFilterCols.includes(colIndex) || header.hasClass('no-export')) return;
|
|
|
+ // Skip filter if column is in skipFilterCols or has 'no-export' class
|
|
|
+ if (header.hasClass('no-export')) return;
|
|
|
+
|
|
|
+ // --- FILTER BUTTON AND DROPDOWN ---
|
|
|
+ const filterBtn = $('<button type="button" class="filter-btn">⬇</button>').appendTo(header);
|
|
|
+ const dropdown = $('<div style="opacity: 1; background: white; overflow-y: auto; max-height: 400px;" class="floating-filter-dropdown"></div>').appendTo('body').hide();
|
|
|
+
|
|
|
+ // Unique sorted values
|
|
|
+ const uniqueValues = column.data()
|
|
|
+ .unique()
|
|
|
+ .toArray()
|
|
|
+ .filter(d => d != null && d !== '')
|
|
|
+ .map(d => d.toString())
|
|
|
+ .sort((a,b) => a.localeCompare(b));
|
|
|
+
|
|
|
+ // "All" checkbox
|
|
|
+ const allCheckbox = $(`
|
|
|
+ <div>
|
|
|
+ <input type="checkbox" id="all_${colIndex}" value="all" checked>
|
|
|
+ <label for="all_${colIndex}">All</label>
|
|
|
+ </div>
|
|
|
+ `);
|
|
|
+ dropdown.append(allCheckbox);
|
|
|
+
|
|
|
+ // Individual checkboxes
|
|
|
+ uniqueValues.forEach(val => {
|
|
|
+ const id = `filter_${colIndex}_${val.replace(/\s+/g,'_')}`;
|
|
|
+ const checkbox = $(`
|
|
|
+ <div>
|
|
|
+ <input type="checkbox" id="${id}" value="${val}" checked>
|
|
|
+ <label for="${id}">${val}</label>
|
|
|
+ </div>
|
|
|
+ `);
|
|
|
+ dropdown.append(checkbox);
|
|
|
+ });
|
|
|
+
|
|
|
+ // --- Checkbox handling ---
|
|
|
+ dropdown.on('change', 'input[type=checkbox]', function () {
|
|
|
+ const allChecked = allCheckbox.find('input').prop('checked');
|
|
|
+
|
|
|
+ if ($(this).val() === 'all') {
|
|
|
+ const checked = $(this).prop('checked');
|
|
|
+ dropdown.find('input[type=checkbox]').prop('checked', checked);
|
|
|
+ } else {
|
|
|
+ const total = dropdown.find('input[type=checkbox]').not('[value="all"]').length;
|
|
|
+ const checkedCount = dropdown.find('input[type=checkbox]:checked').not('[value="all"]').length;
|
|
|
+ allCheckbox.find('input').prop('checked', checkedCount === total);
|
|
|
+ }
|
|
|
+
|
|
|
+ const selectedValues: string[] = dropdown.find('input[type=checkbox]:checked').not('[value="all"]').map((i, el) => $(el).val()?.toString() || '').get();
|
|
|
+ if (selectedValues.length === 0 || allChecked) column.search('').draw();
|
|
|
+ else {
|
|
|
+ // const regex = selectedValues.map(v => $.fn.dataTable.util.escapeRegex(v)).join('|');
|
|
|
+ const regex = selectedValues.map(v => '^' + $.fn.dataTable.util.escapeRegex(v) + '$').join('|');
|
|
|
+ column.search(regex, true, false).draw();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // --- Show/hide dropdown ---
|
|
|
+ filterBtn.on('click', function (e) {
|
|
|
+ e.stopPropagation();
|
|
|
+ const offset = filterBtn.offset();
|
|
|
+ dropdown.css({
|
|
|
+ top: offset.top + filterBtn.outerHeight() + 2,
|
|
|
+ left: offset.left,
|
|
|
+ position: 'absolute',
|
|
|
+ zIndex: 1000
|
|
|
+ }).toggle();
|
|
|
+ });
|
|
|
+
|
|
|
+// Prevent clicks inside the dropdown from closing it
|
|
|
+dropdown.on('click', function (e) {
|
|
|
+ e.stopPropagation(); // stops the document click from firing
|
|
|
+});
|
|
|
+
|
|
|
+// Only hide dropdown when clicking outside
|
|
|
+$(document).on('click', function () {
|
|
|
+ dropdown.hide();
|
|
|
+});
|
|
|
+ });
|
|
|
+},
|
|
|
buttons: [
|
|
|
{
|
|
|
extend: 'print',
|
|
|
@@ -164,7 +275,7 @@ export class CustomerComponent implements OnInit {
|
|
|
//error occured
|
|
|
this.openPopup();
|
|
|
this.status_msg = "Warning";
|
|
|
- this.error_msg = response.errors;
|
|
|
+ this.error_msg = response.error;
|
|
|
} else {
|
|
|
//succeessful response
|
|
|
if (response.data[0].createcustomerStatus == 0) {
|
|
|
@@ -191,7 +302,7 @@ export class CustomerComponent implements OnInit {
|
|
|
// console.log("inside if")
|
|
|
// this.openPopup();
|
|
|
// this.status_msg = "Warning";
|
|
|
- // this.error_msg = response.errors;
|
|
|
+ // this.error_msg = response.error;
|
|
|
// } else if (response.data.length > 0) {
|
|
|
|
|
|
// this.openPopup();
|
|
|
@@ -204,7 +315,7 @@ export class CustomerComponent implements OnInit {
|
|
|
// if (response.data[0].exception.errorid != '') {
|
|
|
// this.openPopup();
|
|
|
// this.status_msg = "Warning";
|
|
|
- // this.error_msg = response.errors;
|
|
|
+ // this.error_msg = response.error;
|
|
|
// }
|
|
|
// }
|
|
|
// else {
|
|
|
@@ -217,7 +328,7 @@ export class CustomerComponent implements OnInit {
|
|
|
// //console.log("inside if")
|
|
|
// this.openPopup();
|
|
|
// this.status_msg = "Warning";
|
|
|
- // this.error_msg = response.errors;
|
|
|
+ // this.error_msg = response.error;
|
|
|
// }
|
|
|
// else if (response.data.length > 0) {
|
|
|
// //console.log("inside if(response.message== '')222222222222 ")
|
|
|
@@ -235,7 +346,7 @@ export class CustomerComponent implements OnInit {
|
|
|
// if (response.data[0].exception.errorid != '') {
|
|
|
// this.openPopup();
|
|
|
// this.status_msg = "Warning";
|
|
|
- // this.error_msg = response.errors;
|
|
|
+ // this.error_msg = response.error;
|
|
|
// }
|
|
|
// }
|
|
|
// else {
|
|
|
@@ -367,7 +478,7 @@ addTask(customerId: string, userId: string) {
|
|
|
//error occured
|
|
|
this.openPopup();
|
|
|
this.status_msg = "Warning";
|
|
|
- this.error_msg = response.errors || response.mesasge;
|
|
|
+ this.error_msg = response.error || response.mesasge;
|
|
|
} else {
|
|
|
//succeessful response
|
|
|
if (response.updateCustomerStatus == 0) {
|