Hi all, I’m trying to add checkboxes to a table and put a button in the bottom row to action on the checked boxes.
I’ve managed to get a button in the final row, however, it vanishes once the page has loaded! The images below show the same problem but with a checkbox.
Does anyone know why this is? I’m using the code from the Knack Dev doc examples (also shown below).
// Function that adds checkboxes
var addCheckboxes = function(view) {
// Add the checkbox to to the header to select/unselect all
$('#' + view.key + '.kn-table thead tr').prepend('<th><input type="checkbox"></th>');
$('#' + view.key + '.kn-table thead input').change(function() {
$('.' + view.key + '.kn-table tbody tr input').each(function() {
$(this).attr('checked', $('#' + view.key + '.kn-table thead input').attr('checked') != undefined);
});
});
// Add a checkbox to each row in the table body
$('#' + view.key + '.kn-table tbody tr').each(function() {
$(this).prepend('<td><input type="checkbox"></td>');
});
}
// Add checkboxes to a specific table view (view_1). Replace view_1 with your view key
$(document).on('knack-view-render.view_226', function (event, view) {
addCheckboxes(view);
});
// Cycle through selected checkboxes. Use this in any code that needs to get the checked IDs
$('#view_226 tbody input[type=checkbox]:checked').each(function() {
// add code here to get record id or row value
var id = $(this).closest('tr').attr('id'); // record id
});