Skip to content

Commit 0cc0281

Browse files
authored
fix: Fix table sort functionality for tables with colspan attributes (ietf-tools#4605)
Fixes ietf-tools#4555
1 parent 9b4903e commit 0cc0281

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

ietf/static/js/list.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ function replace_with_internal(table, internal_table, i) {
2424
}
2525

2626
function field_magic(i, e, fields) {
27-
if ($(e)
28-
.attr("colspan") === undefined &&
29-
(fields[i] == "num" || fields[i] == "count" ||
30-
fields[i] == "percent" || fields[i] == "id" ||
31-
fields[i].endsWith("-num") || fields[i].endsWith("-date"))) {
27+
if (fields[i] == "num" || fields[i] == "count" ||
28+
fields[i] == "percent" || fields[i] == "id" ||
29+
fields[i].endsWith("-num") || fields[i].endsWith("-date")) {
3230
$(e)
3331
.addClass("text-end");
3432
}
@@ -62,12 +60,21 @@ $(document)
6260
// get field classes from first thead row
6361
var fields = $(header_row)
6462
.find("th, td")
65-
.map(function () {
66-
return $(this)
67-
.attr("data-sort") ? $(this)
63+
.toArray()
64+
.map((el) => {
65+
let colspan = parseInt($(el)
66+
.attr("colspan")) || 1;
67+
// create a dense (non-sparse) array
68+
let data_sort = new Array();
69+
for (var i = 0; i < colspan; i++) {
70+
data_sort[i] = "";
71+
}
72+
data_sort[0] = $(el)
73+
.attr("data-sort") ? $(el)
6874
.attr("data-sort") : "";
75+
return data_sort;
6976
})
70-
.toArray();
77+
.flat();
7178

7279
if (fields.length == 0 || !fields.filter(field => field != "")) {
7380
// console.log("No table fields defined, disabling search/sort.");

0 commit comments

Comments
 (0)