From 03b0a7f2effff6741feecacc41e70f0e4bb63da3 Mon Sep 17 00:00:00 2001 From: Kevin Marks <38101946+kevinmarks-b@users.noreply.github.com> Date: Tue, 31 Jan 2023 19:58:15 +0000 Subject: [PATCH] Check that the table has a body before trying to iterate it Without this, a table with a but no rows in the body will cause an error, and tables further down the page will not be sortable any more. --- sorttable/sorttable.js | 48 ++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/sorttable/sorttable.js b/sorttable/sorttable.js index a6b65b0..17c8c35 100644 --- a/sorttable/sorttable.js +++ b/sorttable/sorttable.js @@ -167,29 +167,31 @@ sorttable = { guessType: function(table, column) { // guess the type of a column based on its first non-blank row sortfn = sorttable.sort_alpha; - for (var i=0; i 12) { - // definitely dd/mm - return sorttable.sort_ddmm; - } else if (second > 12) { - return sorttable.sort_mmdd; - } else { - // looks like a date, but we can't tell which, so assume - // that it's dd/mm (English imperialism!) and keep looking - sortfn = sorttable.sort_ddmm; + if (table.tBodies[0]){ + for (var i=0; i 12) { + // definitely dd/mm + return sorttable.sort_ddmm; + } else if (second > 12) { + return sorttable.sort_mmdd; + } else { + // looks like a date, but we can't tell which, so assume + // that it's dd/mm (English imperialism!) and keep looking + sortfn = sorttable.sort_ddmm; + } } } }