logo

demo

Unnamed repository; edit this file 'description' to name the repository.
commit: 2584507fdbbd2a5de65dcf5beac66d2882c9d25c
parent: 8e104283eef17e639c196354f86cc262b1125b73
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat, 13 Apr 2019 18:42:46 +0200

sorttable/sorttable.js: fallback on empty cells

Diffstat:

Msorttable/sorttable.js12++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/sorttable/sorttable.js b/sorttable/sorttable.js @@ -60,22 +60,26 @@ sorttable = { // sort based on the sort keys, and then put the rows back in order // which is a lot faster because you only do getInnerText once per row row_array = []; - col = this.sorttable_columnindex; - rows = this.sorttable_tbody.rows; + col = tr.sorttable_columnindex; + rows = tr.sorttable_tbody.rows; for (var j = 0; j < rows.length; j++) { row_array[row_array.length] = [ sorttable.getElementValue(rows[j].cells[col]), rows[j] ]; } row_array.sort().reverse(); - tb = this.sorttable_tbody; + tb = tr.sorttable_tbody; row_array.forEach(function(row) { tb.appendChild(row[1]); }); delete row_array; - this.classList.add('sorttable_sorted'); + tr.classList.add('sorttable_sorted'); } }, // Use data-value="" attribute if you want to override innerHTML // Example: <td data-value="1337">Leet</td> getElementValue : function(element) { + if(element === undefined) { + return "\u0000"; // null + console.log("Warning: Empty cells found"); + } if (element.dataset.value) { return element.dataset.value; } else {