To navigate to a list view, set the list view ID on the listViewId attribute and fire the event. This example displays the list views for contacts.
gotoList : function (component, event, helper) { var action = component.get("c.getListViews"); action.setCallback(this, function(response){ var state = response.getState(); if (state === "SUCCESS") { var listviews = response.getReturnValue(); var navEvent = $A.get("e.force:navigateToList"); navEvent.setParams({ "listViewId": listviews.Id, "listViewName": null, "scope": "Contact" }); navEvent.fire(); } }); $A.enqueueAction(action); }
This Apex controller returns all list views for the contact object.
@AuraEnabled public static List<ListView> getListViews() { List<ListView> listviews = [SELECT Id, Name FROM ListView WHERE SobjectType = 'Contact']; // Perform isAccessible() check here return listviews; }
You can also provide a single list view ID by providing the list view name you want to navigate to in the SOQL query.
SELECT Id, Name FROM ListView WHERE SobjectType = 'Contact' and Name='All Contacts'
Attribute Name | Type | Description | Required? |
---|---|---|---|
listViewId | String | The ID of the list view to be displayed. | Yes |
listViewName | String | Specifies the name for the list view and doesn’t need to match the actual name. To use the actual name that’s saved for the list view, set listViewName to null. | |
scope | String | The name of the sObject in the view, for example, “Account” or “namespace__MyObject__c”. |