The JavaScript to do this task is well known. It is simply a case of finding how to deliver it into the web page. Options include
- a view
- a form
- a (Gutenberg) content block
In this first implementation I am using a form.
- In your view have the tag <table id="tableId">
- Create a new form
- Add a hidden field to it (this will not be used)
- Settings > General >
- On Submit > Redirect to URL = ./
- Do not store entries
- Check Ajax options
- Settings > Form Actions
- Delete all
- Customise HTML
- delete form classes
- delete before fields
- After fields =
//from https://stackoverflow.com/questions/2044616/select-a-complete-table-with-javascript-to-be-copied-to-clipboard <script> function selectElementContents(el) { var body = document.body, range, sel; if (document.createRange && window.getSelection) { range = document.createRange(); sel = window.getSelection(); sel.removeAllRanges(); try { range.selectNodeContents(el); sel.addRange(range); } catch (e) { range.selectNode(el); sel.addRange(range); } document.execCommand("copy"); } else if (body.createTextRange) { range = body.createTextRange(); range.moveToElementText(el); range.select(); range.execCommand("Copy"); } alert("Table copied to clipboard. You can now paste it into Excel or another application"); } </script>
4. Submit Button
<div class="frm_submit"> <input type="button" value="Copy table" onclick="selectElementContents( document.getElementById('tableId') );"> </div>