function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Cloud EliteCloud Elite 

how to keep the tab referencing a list view not to open in new window but instead should stay within ?

hello all, 

i had to create a custom tab and link it to a ligening compoent so tht if i click on the tab, i will open a list view i created on the account object. I did that but it opens in a new window while i want to keep it within the current window. here is what i created: 

cmp 
 
<aura:component implements="force:appHostable" >
	<aura:handler name="init" value="{!this}" action="{!c.init}"/>
</aura:component>

js
 
({
    init : function(component, event, helper) {
        window.open("one/one.app#/sObject/Account/list?filterName=00B3D000001YKO7UAO",'_target');
        window.history.back();
    }
})

i am hopping there is someting else to relpace the window.open to something else to keep the page within the current one. any help ? ​
Best Answer chosen by Cloud Elite
Narender Singh(Nads)Narender Singh(Nads)
Hi,
In your code you're trying to navigate to a list view of Account object.

If you want to navigate using standard event then, your code will look like this:
 
({
    init : function(component, event, helper) {
        var navEvent = $A.get("e.force:navigateToList"); 
        navEvent.setParams({ 
            "listViewId": '00B6A0000070O0bUAE',// 
            "listViewName": null,
            "scope": "Account" 
        });
        navEvent.fire();
    }
      
})
IMPORTANT NOTE:
The thing about this piece of code is,  everytime you will open that tab,you will be redirected that list view page.
But according to your requirement, you want that list view to show in your component and not to go get redirected to your page(please correct me if am wrong).

So now in order to do that, remove the init function code in your JS Controller and use this piece of code in your component code:
 
<lightning:listView objectApiName="Account"
     			    listName="AllAccounts"
    				showActionBar="false"
    				enableInlineEdit="true"
    				showRowLevelActions="false"/>
Note: 
listName="AllAccounts", in this line replace 'AllAccounts' with the developer name(Api name) of your ist view.

To find the developer name to simply run a SQOL in your query editor:
Select DeveloperName from listview where id ='00B6A0000070O0bUAE'

Let me know if it helps,
Thanks

All Answers

Waqar Hussain SFWaqar Hussain SF
Use below code
({
    init : function(component, event, helper) {
        window.location = "one/one.app#/sObject/Account/list?filterName=00B3D000001YKO7UAO";
        //window.history.back();
    }
})

 
Narender Singh(Nads)Narender Singh(Nads)
I wouldn't suggest using window.location.
You should use force:navigateToUrl event
https://developer.salesforce.com/docs/component-library/bundle/force:navigateToURL/documentation

Refer this documentation to know more about it.
 
Cloud EliteCloud Elite
this is what i am using @Narender , how would you adjust it to meet that documenttion ? 

cmp 
<aura:component implements="force:appHostable" >
    <aura:handler name="init" value="{!this}" action="{!c.init}"/>
</aura:component>

and currecnt js
 
({
    init : function(component, event, helper) {
        window.open("one/one.app#/sObject/Account/list?filterName=00B6A0000070O0bUAE",'_target');
        window.history.back();
    }
      
})

Narender Singh(Nads)Narender Singh(Nads)
Hi,
In your code you're trying to navigate to a list view of Account object.

If you want to navigate using standard event then, your code will look like this:
 
({
    init : function(component, event, helper) {
        var navEvent = $A.get("e.force:navigateToList"); 
        navEvent.setParams({ 
            "listViewId": '00B6A0000070O0bUAE',// 
            "listViewName": null,
            "scope": "Account" 
        });
        navEvent.fire();
    }
      
})
IMPORTANT NOTE:
The thing about this piece of code is,  everytime you will open that tab,you will be redirected that list view page.
But according to your requirement, you want that list view to show in your component and not to go get redirected to your page(please correct me if am wrong).

So now in order to do that, remove the init function code in your JS Controller and use this piece of code in your component code:
 
<lightning:listView objectApiName="Account"
     			    listName="AllAccounts"
    				showActionBar="false"
    				enableInlineEdit="true"
    				showRowLevelActions="false"/>
Note: 
listName="AllAccounts", in this line replace 'AllAccounts' with the developer name(Api name) of your ist view.

To find the developer name to simply run a SQOL in your query editor:
Select DeveloperName from listview where id ='00B6A0000070O0bUAE'

Let me know if it helps,
Thanks
This was selected as the best answer