I have a table with a mass action attached to it. I’d like to be able to trigger that action in a snippet.
There’s likely a better way, but I was able to do this by using jQuery to target the button which normally triggers the desired mass action and then forcing a click on it. Here’s my code:
var $ = skuid.$, action = arguments.action, list = arguments.list, model = arguments.model; // Force all checkboxes (for each table row) into checked state $('#sk-3GF2wd-4635 input[type=checkbox]').prop("checked",true); // Trigger a click on the button which triggers the mass action $("#followupTable div.nx-massactions div:eq(0)").click();
I found the selector for the checkboxes and the mass action using Chrome’s devtools. There are a lot of guides around if you’re unsure of how to do this yourself. Here’s a decent one.
Here’s how I attached the snippet to a save button on my layout:
Hope this helps and I’m happy to help clarify if needed. Also curious if anyone found a “nicer” way of doing this.
Thanks for posting this! You might find this method a little “nicer”, as it doesn’t require manually picking out DOM elements:
var $ = skuid.$, list = arguments.list, selectedItems = list.getSelectedItems();
selectedItems should return information about the associated element, row, etc.
Hope this helps!