Storing Row ID's when selected

Storing Row ID's when selected

nickkeehannickkeehan Posts: 2Questions: 2Answers: 0

Hey guys.

Novice here, and trying to combine Salesforce and Datatables.

I can select rows in Datatable, however i am looking to get an ID off the row when selected. So create an Array of ID's from rows when selected.

The data is being provided by a server Side class, so pulling via Ajax as some examples suggest wont work for me i dont believe.

Does anyone know how to pick up the ID of the row selected when the data is housed on the page through a class?

============================= Page Snippet=========================

                    <aura:iteration items="{!v.lstAcc}" var="acc" >
                        <tr>
                            <td><div class="slds-truncate" title="{!acc.Id}">{!acc.Name}</div></td>
                            <td><div class="slds-truncate" title="{!acc.ShippingState}">{!acc.ShippingState}</div></td>
                            <td><div class="slds-truncate" title="{!acc.ShippingCity}">{!acc.ShippingCity}</div></td>
                            <td><div class="slds-truncate" title="{!acc.Area_Unit__c}">{!acc.Area_Unit__c}</div></td>        
                            <td><div class="slds-truncate" title="{!acc.Territorial_Local_Authority__c}">{!acc.Territorial_Local_Authority__c}</div></td>                                 
                            <td><div class="slds-truncate" title="{!acc.Emergency_Contact_Name__c}">{!acc.Emergency_Contact_Name__c}</div></td>                        
                        </tr>                    
                    </aura:iteration>  

<button class="slds-button slds-button--brand" onclick="{!c.addSelected}">Add Selected Schools</button>

=================================JS==============================

               $('#tableId').DataTable({
                                columnDefs: [ {
                                            orderable: true,
                                            className: 'select-checkbox',
                                            targets:   0
                                            } ],                   
                                   select: {
                                            style: 'multi'
                                            },                     
                                      dom: 'Bfrtip',
                                   buttons: [
                                           {
                                               text: "Select Results",
                                               action: function ( e, dt, button, config ) {
                                                   dt.rows( { search: 'applied' } ).select();
                                               }
                                            },
                                           'selectNone'
                                             ]               
                           });

Any help would be appreciated.

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @nickkeehan ,

    You should be able to use one of the events, such as selectItems to get the rows that are currently selected.

    Cheers,

    Colin

This discussion has been closed.