'Select' button in tables and lists

As a builder of multiple apps, I want to be able to select a record from a table or list so that I can then perform an action on the selected records.

It would be great to be able to perform an action on a number of records manually selected. I have had a number of situations where this would be useful, but in essence I want to be able to ‘add to basket’ (or change status to received or authorise or whatever).

This seems such a common and effective way of performing an action on multiple manually selected records on so many sites / platforms and I think it would add functionality to so many Knack apps. A prime example is in the Knack Builder in the Records tab…

As a [type of user], I want to [perform a specific task] so that I can [achieve a certain goal].

I can get you script that will batch update records . Shout out if you would like

Thanks Jonathan,

I’d be curious to see the script so please send across, but I still feel this should be part of the Knack basic functionality, and would be so widely applicable for almost any builder / user.

Many thanks

if you have questions give me a shout at avdataco@gmail.com


//JT-this code for adding checkboxes that reconcile multiple receipts at once

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>');
});
}


/**** CHANGE VIEW_ID TO YOUR OWN VIEW ID ****/
$(document).on('knack-view-render.view_000, function(event, view) {

// Add an update button
$('<button id="update"">RECONCILE Selected</button>').insertAfter('.kn-records-nav');

// Add checkboxes to our table
addCheckboxes(view);

// Click event for the update button
$('#update').click(function() {

// We need an array of record IDs
var record_ids = [];

// Populate the record IDs using all checked rows
$('#' + view.key + ' tbody input[type=checkbox]:checked').each(function() {
record_ids.push($(this).closest('tr').attr('id')); // record id
});

//Knack.showSpinner();

// Define the fields you want to update
var data = {
field_0000: 'Reconciled',
//field_12: 'Hold',
//field_18: 10
};

// seet the delay to prevent hitting API rate limit (milliseconds)
var myDelay = 100;

//call updateRecords function
$(function() {
updateRecords(record_ids.shift(), record_ids, data);
});

var selectedRecords = record_ids.length + 1
function updateRecords(id, records, data) {

$.ajax({
//CHANGE OBJECT_ID TO YOUR OWN OBJECT ID
url: 'https://api.knackhq.com/v1/objects/object_00/records/' + id,
type: 'PUT',
/***** CHANGE TO YOUR OWN APPID AND API KEY HERE *****/
headers: {
'X-Knack-Application-ID': '0000000000',
'X-Knack-REST-API-Key': '0000000000000'
},
data: data,
success: function(response) {
if (record_ids.length > 0) {
// Every time a call is made, the array is shifted by 1.
// If the array still has a length, re-run updateRecords()
setTimeout(updateRecords(record_ids.shift(), record_ids, data), myDelay);
} else {
alert(selectedRecords + " receipts have been marked as reconciled");
Knack.hideSpinner();
location.reload();
}
}
})
}
})
});

1 Like

Thanks @JonathanTack, very kind. I am not at a level yet to deploy this script, but helpful all the same and hopefully of use to other users too!

@Hugo i’m more than happy to walk you through it. it would take us less than 30 mins on a screenshare & phone call.

Hi Jonathan,

That would be great – what timezone are you on? I am in the UK.

Thanks a lot!

USA central …
Let’s move to email
AvDataco@gmail.com

@Hugo - a valid feature request that we would love to offer out of the box, it has been blocked for some time, unfortunately. Please follow along/vote on this existing request here that we’re tracking: Update Multiple Records at once

Our dev docs cover adding the checkboxes by the way (JavaScript & jQuery Examples), but does not include any action, which is what @JonathanTack has appended with. Thanks for sharing your code, Jonathan! Hope a custom solution can help in the meantime.

3 Likes

Hi Jonathan, is it possible to use your code to trigger an action like, for example, send an email to all the checked records in a contact table?

HI Jaime,

this is not possible in Knack natively.
you’d need to crank up Integromat. I can help you toward that.

Thank you. I’m using Zapier already but I thought your code could be extended to something like that. Thanks. Lets keep in touch.

sounds good!

Reaching out for some help.

I’d like to filter/temporarily select multiple records from a table using checkboxes to then export the selected records in this instance. I’ve created the checkboxes but don’t know how to get to the next step to be able export the selected records.

Suggest contacting @JonathanTack, looks like he could create the custom JavaScript for your request.

Thank you.

1 Like