2

I am trying to use lightning:listView to fulfill a requirement for a project I am working on.

An important part of this requirement is that I need to be able to fire an event that will return the currently selected records of the listView, but I haven't yet found a way to get the listView object to expose what is currently selected in the javascript controller.

(I would much rather use native aura functionality to figure this out instead of using hacking it by using javascript vs the DOM, and this seems like the sort of thing that should be supported natively.)

Here is a simplified version of what I am trying to do, where the event is just being fired by a lightning:button:

Contacts.listView-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<ListView xmlns="http://soap.sforce.com/2006/04/metadata">
    <fullName>Contacts</fullName>
    <columns>FULL_NAME</columns>
    <columns>ACCOUNT.NAME</columns>
    <columns>CONTACT.PHONE1</columns>
    <columns>CONTACT.EMAIL</columns>
    <columns>CONTACT.TITLE</columns>
    <columns>CORE.USERS.ALIAS</columns>
    <filterScope>Everything</filterScope>
    <label>Contacts</label>
</ListView>

ContactListView.cmp:

<aura:component implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,forceCommunity:availableForAllPageTypes" access="global" >
    <lightning:listView aura:id="listViewOfContacts"
        objectApiName="Contact"
        listName="Contacts"
        rows="25"
        showSearchBar="true"
        showActionBar="true"
        enableInlineEdit="true"
        showRowLevelActions="true"
    />
    <lightning:button label="Get Currently Selected" title="Get Currently Selected" onclick="{! c.handleGetCurrentlySelected }"/>
</aura:component>

ContactListViewController.js

({
    handleGetCurrentlySelected: function(component, event, helper)  {
       var listViewContacts = component.find('listViewOfContacts');
//***I need to get the set of curently selected record here***
    }
})

What I have tried:

1) I tried to use the approach suggested here, which would be to call getSelectedRows on my object from my example like this:

listViewContacts.getSelectedRows();

...but that method isn't available and I haven't found any documentation that indicates that this approach could work.

2) I also tried to expose the methods that can be called on the listViewContacts var from my example's javascript controller using this method and got the following list:

0: "toString"
1: "addValueHandler"
2: "addValueProvider"
3: "destroy"
4: "getGlobalId"
5: "getLocalId"
6: "getEvent"
7: "isInstanceOf"
8: "isRendered"
9: "isValid"
10: "set"
11: "get"
12: "addHandler"

This list isn't encouraging, as I don't see any methods that look like they would do what I want.

3) I also tried to use this method to create a recordId attribute that would hopefully be populated with a json of the selected records or something. The recordId attribute was not populated, which I assume is because this isn't a record page, so that is another dead end.

4) I also tried to just get at the values from looking at it through the DOM directly, but I haven't been able to figure out how to do that with the lightning locker restrictions. At this point, I would be happy to select an answer that shows how to just pull this information non-natively by looking at the DOM.

a) I did try statically loading jquery adding the following to my .cmp file:

<ltng:require scripts="{!$Resource.zippedResourceBundle +'/path/to/jquery/in/zip/jquery.min.js'}" afterScriptsLoaded="{!c.loadJquery}" />

and was able to verify that jquery loaded and could be used without errors, but I wasn't able to use it to traverse the DOM. Everything I tried didn't work, which I believe is from the lightning locker restrictions.

b) I was able to get a response back from

console.log(component.getElements());

but I haven't figured out a good way of figuring out what I need from it yet.

How can I natively get the list of currently selected records from lightning:listView in the javascript controller?

(parallel posted to the Salesforce developer forum)

1

It turns out that this is not possible right now.

I was able to get in contact with the appropriate folks on the Salesforce development team that is responsible for this lightning component and they confirmed that there is no way to make this work. However, it is on their roadmap to add it in.

In the meantime, the closest approximation to what I was trying to do is via the DataTable component.

If you are using datatable component, you can use component.find('auraIdOfYourdataTable').getSelectedRows(); to get what I was trying to do here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.