Getting the selected records on a table without using mass/row action and instead using a button

  • 1
  • Question
  • Updated 3 years ago
  • Answered
Hello!

When starting a snippet using code such as that shown below, is it possible to pull in selected items from a table by clicking on a title button that launches a snippet or does the snippet always have to be run from a mass action or row action on the table?

Cheers guys!

var params = arguments[0],
   $ = skuid.$,
   items = params.item ? [params.item] : params.list.getSelectedItems()
Photo of Louis Skelton

Louis Skelton

  • 4,858 Points 4k badge 2x thumb
  • exceedingly good

Posted 4 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Yes, you just need to get a reference to the Table's list. This is doable several ways, but the easiest way is to give your Table a Unique Id, e.g. "MyTable", and then you could call this from your button:

var table = skuid.$('#MyTable'),
   list,
   items;
if (table.length) {
   list = table.data('object').list;
   items = list.getSelectedItems();
}
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
Needed this code tonight -- Thanks!!!
(Edited)
Photo of Louis Skelton

Louis Skelton

  • 4,858 Points 4k badge 2x thumb
Worked a treat!

Cheers Zach. This will be tremendously useful.