Bugfix Issue 799 Quick Search Empty Table - sebiboga/testlink-upgraded GitHub Wiki

Bugfix Issue #799 — Quick Search: empty results table when the DataTables CDN is unavailable

Symptom

On the Quick Search screen (gui/templates/search/searchQuickView.html), clicking Find intermittently rendered Search results (N matches) + a N matches footer, but the results table body stayed EMPTY (no row). This was intermittent and happens "from time to time".

Empty table (pre-fix)

Root Cause

The page loads jQuery + DataTables from external CDNs (searchQuickView.html:115-117 — code.jquery.com, cdn.datatables.net). If the CDN is slow/unavailable at the moment the user clicks Find, $.fn.DataTable is undefined.

renderResults() showed the count/wrapper first, then unconditionally called $('#resTable').DataTable(...):

  • :215 shows #matchCount ("(1 matches)");
  • :226 shows #resultsWrap;
  • :242 called $('#resTable').DataTable({...}) with no guard.

When $.fn.DataTable is undefined, that call throws (Uncaught TypeError: $(...).DataTable is not a function), aborting renderResults() after the count/wrapper were already shown — leaving the count visible beside an empty table body. The Find button also stayed disabled because the unhandled throw prevented the $.getJSON(...).always(...) callback from re-enabling it.

Fix

renderResults() in searchQuickView.html:

  1. Renders a plain HTML <tbody> first (via jQuery), so the matched rows always display regardless of DataTables availability.
  2. Only then tries the DataTables enhancement, guarded by typeof $.fn.DataTable === 'function' and wrapped in try/catch — if it fails, the plain table remains.
  3. The up-front teardown now also nulls resTbl (if (resTbl) { resTbl.destroy(); resTbl = null; ... }).

This keeps the count consistent with the rendered rows and lets the Find button re-enable (.always() runs — no unhandled throw). No new user-facing strings were added, so no i18n bundle changes were required.

Fallback table rendered (post-fix)

Verification

  • Fallback scenario ($.fn.DataTable = undefined, then Find): table renders the row (TLU-1 [v1] :: Login works, summary, version, edit/history buttons), 1 matches footer, Find button re-enabled, no console JS error.
  • Normal scenario (DataTables present, then Find): enhanced DataTables table still renders with search box, pagination and sorting — no regression.
  • Event Viewer (events table): no new Error/Warning (log_level 3/4) entries.

Affected Files

  • gui/templates/search/searchQuickView.html
⚠️ **GitHub.com Fallback** ⚠️