Javascript for rows that are checked in a table?

  • 1
  • Question
  • Updated 3 years ago
  • Answered
I need to write some code to run a loop only on the rows that are checked in a table. How do I reference the checked table rows in javascript?
Photo of Anna Orias

Anna Orias

  • 1,468 Points 1k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
You'll need to give your table a unique name e.g. my-table.
var myTable = skuid.$('#my-table').data('object');
var selectedItems = list.getSelectedItems();
$.each(selectedItems, function (i, item) {
    console.log(i + ' - ' + item);
});
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Thanks Irvin
Photo of Zach McElrath

Zach McElrath, Employee

  • 48,984 Points 20k badge 2x thumb
Another Community post that might be helpful here:

https://community.skuidify.com/skuid/topics/how_to_add_marketo_send_email_mass_action_to_a_skuid_tab...

And here's the documentation on writing Mass Action Snippets, which leverage the "getSelectedItems()" behavior Irwin described:

http://help.skuidify.com/m/11720/l/204930-table-component-custom-mass-actions
Photo of Anna Orias

Anna Orias

  • 1,468 Points 1k badge 2x thumb
Thanks everyone! We got it working as a mass action...

var params = arguments[0], $ = skuid.$,
    action = arguments[0].action,
    list = arguments[0].list,
    model = arguments[0].model,
    selectedItems = list.getSelectedItems();

var SessionModelId=skuid.model.getModel("MMA_Academy_Student_Event_Session_included").data[0].Id;

if(SessionModelId) {

    var SessionPerformerModel=skuid.model.getModel("MMA_Academy_Student_Event_Session_Perfor");

    $.each( selectedItems,
        function( i, item )
        {
            var row = item.row;
            console.log(row.Id);
            var newRow=SessionPerformerModel.createRow({
                additionalConditions: [
                    {field:'MMA_Academy_Student_Event_Performer__c', value:row.Id},
                    {field:'MMA_Academy_Student_Event_Session__c', value:SessionModelId},
                    
                    ], doAppend: true
            });
        });
        SessionPerformerModel.save({callback: function(result){
        if (result.totalsuccess) {
            alert('Performers were added to the selected sessions');
        } else {
            console.log(result.insertResults);
            console.log(result.updateResults);
            console.log(result.deleteResults);      
        }
    }});
}

else{
    alert('Select a session to add the performers to.');
}
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
I'm glad you got it working!  Cheers!