Skip to content

Commit

Permalink
Fix searching
Browse files Browse the repository at this point in the history
  • Loading branch information
learn-more committed Dec 13, 2023
1 parent b47b95f commit a32b811
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions layouts/shortcodes/apisetschema_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<tr>
<th>apiset</th>
{{ range $all_versions }}
<th>{{ . }}</th>
<th class="version-col">{{ . }}</th>
{{ end }}
</tr>
</thead>
Expand Down Expand Up @@ -69,44 +69,36 @@
return data;
}
},
targets: '_all'
targets: 'version-col'
},
],
initComplete: function () {
this.api()
.columns()
.columns('.version-col')
.every(function () {
let column = this;

column.render = function ( data, type, row ) {
return '$'+ data;
}

// Create select element
let select = document.createElement('select');
select.add(new Option(''));
select.add(new Option('yes'));
select.add(new Option('no'));
let hdr = $(column.header());
$('<br />').appendTo(hdr);
$(select).appendTo(hdr).click(function(e) { e.stopPropagation(); });
//column.header().replaceChildren(select);

// Apply listener for user change in value
select.addEventListener('change', function () {
var val = DataTable.util.escapeRegex(select.value);

let search_for = '';
if (select.value == 'yes') {
search_for = '.+';
} else if (select.value == 'no') {
search_for = '^$';
}
column
.search(val ? '^' + val + '$' : '', true, false)
.search(search_for, true, false)
.draw();
});

// Add list of options
column
.data()
.unique()
.sort()
.each(function (d, j) {
select.add(new Option(d));
});
});
}
});
Expand Down

0 comments on commit a32b811

Please sign in to comment.