Show users # of items they have selected

  • 1
  • Question
  • Updated 3 years ago
Is there a way to show users how many items they've selected in a list? e.g. at the top of the list, show a template field that displays something like "list.selectedItems.length()"? e.g.



Essentially we want to show users how many items they've chosen before performing a mass action.
Photo of Greg Jarrett

Greg Jarrett

  • 3,496 Points 3k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
Greg,

As soon as I reply, someone is going to tell me that there is a one-line solution.  :)

Here's a quick console hack to get the number of selected items.  Maybe use something like this in a snippet ala custom component?

skuid.$M('Plants').registeredLists[Object.keys(skuid.$M('Plants').registeredLists)[0]].getSelectedItems().length;

where Plants is the name of my model.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
No one line solution here.  Thanks for your answer! 
Photo of Greg Jarrett

Greg Jarrett

  • 3,496 Points 3k badge 2x thumb
Thanks Irvin, I did manage to have a bit of a crack at this one over the weekend, but wasn't able to get it going (admittedly my skuid component building skills need some work too!). What I've done for now is prevented users from executing the mass action (see below) if they select too many items. I also show them an error message at the same time. It's not a perfect solution and I will come back around to it at some point in the future.

//mass create rfq's and quotes from the selected items
var params = arguments[0];
var step = params.step;
var $ = skuid.$;

var models = skuid.model.map();
var list = params.list;

var Ids = skuid.$.map(arguments[0].list.getSelectedItems(),function(item){     
return item.row.Id;});

var max = Ids.length;

if (max > 25) {
    $.blockUI({
    message: "You've selected too many Accounts: " + max + ". Please select a maximum of 25.",
    timeout:3000
    });
} else { //execute the rfq }


Thanks very much for your input here.