Trigger Mass Action via Javascript Snippet

  • 2
  • Question
  • Updated 3 years ago
  • Answered
Is there any way to trigger a mass action on a table via Javascript Snippet.

I have a table with a mass action attached to it.  I'd like to be able to trigger that action in a snippet.

Photo of Chad Hantak

Chad Hantak

  • 80 Points 75 badge 2x thumb

Posted 3 years ago

  • 2
Photo of Kathryn Castle

Kathryn Castle

  • 814 Points 500 badge 2x thumb
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[0].action,
    list = arguments[0].list,
    model = arguments[0].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.
Photo of Emily Davis

Emily Davis, Employee

  • 3,578 Points 3k badge 2x thumb
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[0].list,
    selectedItems = list.getSelectedItems();

selectedItems should return information about the associated element, row, etc.
Hope this helps!