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
lxchlxch 

How to trigger lightning:nagivation with 'open in a new tab' (or open in background tab)

Based on this project (https://trailhead.salesforce.com/ja/content/learn/projects/develop-account-geolocation-app-with-aura-components), I'm working on the aura components that lists the accounts and leads on google map and table compoents of those data, search with search terms and other parameters.

That works fine. 

I want to tweak when I click the "view detail" button then open in a new tab (or open in background tab) instead of refreshing the same tab I was looking at. If anyone has any idea how to open in a new tab, please adivice.

I sense the issue is in the bottom part of the AccountListController.js
Thanks!

AccountListController.js
https://gist.github.com/liuxiachanghong/a2675b44a3f55bdcf864c38787baf438
 

({
    onAccountsLoaded: function( component, event, helper ) {
        var accounts = event.getParam( 'accounts' );
        if (accounts != null) {
            component.set( 'v.iconName', 'standard:account' );
            component.set( 'v.listName', 'Account List' );
            component.set( 'v.rows', event.getParam( 'accounts' ) );
            var cols = [
                {
                    'label': 'Name',
                    'fieldName': 'Name',
                    'initialWidth': 320,
                    'type': 'text'
                },
                {
                    'label': 'Industry',
                    'fieldName': 'Industry',
                    'initialWidth': 190,
                    'type': 'text'
                },
                {
                    'label': 'Type',
                    'fieldName': 'Client_Type_new__c',
                    'initialWidth': 100,
                    'type': 'text'
                },
                {
                    'label': 'Owner',
                    'fieldName': 'Owner_Alias__c',
                    'initialWidth': 110,
                    'type': 'text'
                },
                {
                    'label': 'Last',
                    'fieldName': 'Last_Sales_Activity_By__c',
                    'initialWidth': 110,
                    'type': 'text'
                },
                {
                    'label': 'Last At',
                    'fieldName': 'Last_Sales_Activity__c',
                    'initialWidth': 110,
                    'type': 'date'
                },
                {
                    'label': 'Last Won At',
                    'fieldName': 'Recent_Closed_Won_Date__c',
                    'initialWidth': 110,
                    'type': 'date'
                }, 
                {
                    'label': 'Deal',
                    'fieldName': 'Related_Opportunities_y__c',
                    'type': 'currency'
                },
                {
                    'label': 'Action',
                    'type': 'button',
                    'typeAttributes': {
                        'label': 'Details',
                        'name': 'view_details'
                    }
                }
            ];
        } else {
            component.set( 'v.iconName', 'standard:lead' );
            component.set( 'v.listName', 'Lead List' );
            component.set( 'v.rows', event.getParam( 'leads' ) );          
            var cols = [
                {
                    'label': 'Name',
                    'fieldName': 'LastName',
                    'type': 'text'
                },
                {
                    'label': 'Company',
                    'fieldName': 'Company',
                    'initialWidth': 320,
                    'type': 'text'
                },
                {
                    'label': 'Prefecture',
                    'fieldName': 'State',
                    'type': 'text'
                },
                {
                    'label': 'City',
                    'fieldName': 'City',
                    'type': 'text'
                },
                {
                    'label': 'Street',
                    'fieldName': 'Street',
                    'initialWidth': 320,
                    'type': 'text'
                },
                {
                    'label': 'Type',
                    'fieldName': 'Client_Type_new__c',
                    'type': 'text'
                },
                {
                    'label': 'Owner',
                    'fieldName': 'Owner__c',
                    'type': 'text'
                },
                {
                    'label': 'Action',
                    'type': 'button',
                    'typeAttributes': {
                        'label': 'Details',
                        'name': 'view_details'
                    }
                }
            ];
        }   
        component.set( 'v.cols', cols );
    },
    
    onRowAction: function( component, event, helper ) {
        var accounts = event.getParam( 'accounts' );
        var action = event.getParam( 'action' );
        var row = event.getParam( 'row' );
        if (accounts != null) {
             if ( action.name == 'view_details' ) {
                var navigation = component.find( 'navigation' );
                navigation.navigate({
                    'type': 'standard__recordPage',
                    'attributes': {
                        'objectApiName': 'Account',
                        'recordId': row.Id,
                        'actionName': 'view'
                    }
                });
        	} 
        } else {
            if ( action.name == 'view_details' ) {
                var navigation = component.find( 'navigation' );
                navigation.navigate({
                    'type': 'standard__recordPage',
                    'attributes': {
                        'objectApiName': 'Lead',
                        'recordId': row.Id,
                        'actionName': 'view'
                    }
                });
            }           
        }
    }
})
 


 

AccountList.cmp

https://gist.github.com/liuxiachanghong/705799f378c180a664cd70d52a13b58f

AccountsLoaded.event
https://gist.github.com/liuxiachanghong/c56f9b120ab6c60510db33b473aaeac7


 

Best Answer chosen by lxch
lxchlxch
Removed the action column and use type 'url' (case-sensitive) instead.
Loop the SOQL results (accounts) and stores in rows, then set.
var rows = [];
            for(var i = 0; i < accounts.length; i++){
                var acc = accounts[i];
                rows.push({
                    Id: acc.Id,
                    linkName: '/'+ acc.Id,
                    Name: acc.Name,
                    .....(other fields mapping) ....     
                    });
            }
component.set('v.rows', rows);

In the column section, setup the first columns that display Name while type 'url' and clickable as a link.  Field name is linkName (relabel in type Attributes to the Name.
var cols = [
                {
                    'label': 'Name',
                    'fieldName': 'linkName',
                    'type': 'url',
                    'initialWidth': 420,
                    'typeAttributes': {
                         'label': {
                             'fieldName': 'Name',
                             'target': '_blank'
                         }
                     },
                     'target': '_blank'
                },

..... (other columns) ......
This dones't open the window in the new tab nor background tab, but if you command (ctrl) click then it opens in a new background tab.
Solved.