jQuery(document).ready(function($){// Make sure the table is initialized by DataTables var $table=$('#tablepress-2');var dt=$table.DataTable();// Uses TablePress's DataTables instance

  // Hide table at start
  $table.hide();

  // Also hide info and pagination at start
  $('#tablepress-2_info,#tablepress-2_paginate').hide();

  // Helper: check if the search has any text and if there are results
  function toggleVisibility() {
    var query = $('#tablepress-2_filter input').val().trim();

    // Count filtered rows
    var visibleRows = $table.find('tbody tr:visible').length;

    if (query.length > 0 && visibleRows > 0) {
      // Show table and controls when there is a query and results
      $table.show();
      $('#tablepress-2_info,#tablepress-2_paginate').show();
    } else if (query.length > 0 && visibleRows === 0) {
      // If no matching results, show a brief message, keep table hidden
      $table.hide();
      $('#tablepress-2_info,#tablepress-2_paginate').hide();
      // Optional: show your own "no results" message
      if (!$('#tp2-no-results').length) {
        $('<div id="tp2-no-results" class="tp-no-results">কোনো মিল পাওয়া যায়নি</div>')
          .insertAfter('#tablepress-2_filter');
      }
    } else {
      // Empty query: keep everything hidden
      $table.hide();
      $('#tablepress-2_info,#tablepress-2_paginate').hide();
      $('#tp2-no-results').remove();
    }
  }

  // Listen to typing in the search input
  var debounceTimer;
  $('#tablepress-2_filter input').on('keyup change',function(){clearTimeout(debounceTimer);debounceTimer=setTimeout(toggleVisibility,120)});// Run once in case the page loads with a prefilled query (rare) toggleVisibility()});