Newer Version Available
force:navigateToList
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.
1gotoList : function (component, event, helper) {
2 var action = component.get("c.getListViews");
3 action.setCallback(this, function(response){
4 var state = response.getState();
5 if (state === "SUCCESS") {
6 var listviews = response.getReturnValue();
7 var navEvent = $A.get("e.force:navigateToList");
8 navEvent.setParams({
9 "listViewId": listviews.Id,
10 "listViewName": null,
11 "scope": "Contact"
12 });
13 navEvent.fire();
14 }
15 });
16 $A.enqueueAction(action);
17}This Apex controller returns all list views for the contact object.
1@AuraEnabled
2public static List<ListView> getListViews() {
3 List<ListView> listviews =
4 [SELECT Id, Name FROM ListView WHERE SobjectType = 'Contact'];
5
6 // Perform isAccessible() check here
7 return listviews;
8}You can also provide a single list view ID by providing the list view name you want to navigate to in the SOQL query.
1SELECT 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”. |