Hello! I’m searching for a creative way to quickly copy and paste a column or two of information on the screen without exporting into a csv, then copying and pasting.
Typically, I’m trying to copy emails or phone numbers off a knack table to either email or text our clients.
Does anyone have any creative ways to select a column and simply copy the data out of that column, similar to excel? (I’ve researched some of the apps that would turn knack tables into excel-like spreadsheets, but they are cost prohibitive!)
Next, paste the following code into your app’s JavaScript section, making sure to replace view_xx with your table view ID, and td.field_yy with the field ID of the column you want to copy to the clipboard.
$(document).on('knack-view-render.view_xx', function(event, view, records) {
$('#copyEmails').click(function() { // listen for button click
const td = $('#' + view.key + ' td.field_yy')
copyTdTextToClipboard(td);
});
});
function copyTdTextToClipboard(td) {
let tdTextArray = []; // create an empty array to hold the titles
td.each(function() { // loop through all td elements in the table
var title = $(this).text().trim(); // get the title attribute value of the current td
tdTextArray.push(title); // append the title to the array
});
const textJoin = tdTextArray.join('; '); // join the elements of the tdTextArray into a single string with a semicolon and space separator
navigator.clipboard.writeText(textJoin).then(function() { // copy the textJoin value to the clipboard
console.log('Text copied to clipboard!');
}, function() {
console.error('Failed to copy text to clipboard!');
});
}
When this particular view is rendered, the button will begin listening for a click, and once clicked, will copy all the visible values of your chosen column to the clipboard.
In the below example, I have mapped the button to copy the Contact email column, which will copy all 4 values to the clipboard like so: accounts@abcindustries.com; services@plasterco.com; hello@a1buildingservices.com; orders@glimmerhomes.com