$(document).ready(function () { loader = $('#overlay, #loader'); prTable = $('#PRTable').DataTable({ serverSide: true, processing: true, searching: false, ajax: { url: '/PRMgmt/GetPRArchived', type: 'GET', data: function (d) { return { draw: d.draw, searchPRNo: ($('#srchPRNo').val() || '').trim(), searchItemName: ($('#srchItemName').val() || '').trim(), searchDept: ($('#srchDept').val() || '').trim(), pageNumber: Math.floor(d.start / d.length) + 1, pageSize: d.length }; }, dataSrc: function (json) { return json.data; }, beforeSend: function () { loader.show(); }, complete: function () { loader.hide(); }, error: function (xhr, error) { loader.hide(); console.error('Error loading data:', error); if (typeof toastr !== 'undefined') toastr.error('Failed to load data. Please try again.'); } }, columns: colOnPRTable, order: [[0, 'asc']], language: { emptyTable: "No record available", processing: "Loading…" }, error: errorHandler }); function debounce(fn, delay) { let t; return function (...args) { clearTimeout(t); t = setTimeout(() => fn.apply(this, args), delay); }; } $('#srchPRNo, #srchItemName, #srchDept') .on('keyup', debounce(function () { prTable.ajax.reload(); }, 400)); $('.pr-search-clear').on('click', function () { const target = $(this).data('target'); $(target).val(''); prTable.ajax.reload(); }); }); $(document).on('click', '.toggle-btn', function () { var $button = $(this); var $span = $button.prev('.item-display'); var isExpanded = $button.data('expanded'); if (!isExpanded) { // Show the full content var fullItems = decodeURIComponent($button.attr('data-full-items')); $span.html(fullItems); $button.text('...see less'); } else { // Show the short content var shortItems = decodeURIComponent($button.attr('data-short-items')); $span.html(shortItems); $button.text('...see more'); } // Toggle the expanded state $button.data('expanded', !isExpanded); });