2

I am using a Lightning component that creates a lightning datatable and fills the rows and columns with values get by calling an Apex Class. I want in every line, in one column to use href. For the time being, i use a column type url but when clicking it opens another window whereas i need to redirect the current browser window. Any ideas? Code that i have used: please focus on

component.set('v.columns', [
            {label: 'Customer Code at source system', fieldName: 'linkName', type: 'url', typeAttributes: {
                label: {
                    fieldName: 'CustCode'
                }, 
and on: var returnValue = response.getReturnValue();
                returnValue.forEach(function(record) {
                record.linkName = 'mydomainLink/'+record.CRMCustId+'/view';
            }); 
({
    doInit : function(component, event, helper) {
        component.set("v.spinner", true);
        //ggalaios 2019-10-08 Create the Columns of Lightning Datatable
        component.set('v.columns', [
            {label: 'Customer Code at source system', fieldName: 'linkName', type: 'url', typeAttributes: {
                label: {
                    fieldName: 'CustCode'
                },
                target: '_blank'
            }},
            {label: 'Customer Role Description', fieldName: 'CustRoleDsc', type: 'text'},
            {label: 'Source system', fieldName: 'System_x', type: 'text'},
        ]);
        //03/10/2019: George Galaios: Call Apex Function to call EA Web Service for Parties
        var parties = component.get("c.getParties");          
        parties.setParams({
            //03/10/2019: George Galaios: Set parameters for Apex Function
            "searchDT" : component.get("v.searchDT"),
            "searchLob" : component.get("v.searchLob"),
            "searchSubLob" : component.get("v.searchSubLob"),
            "searchPolicyNum" : component.get("v.searchPolicyNum")
        });
        parties.setCallback(this, function(response) {
            var stateParties = response.getState();
            if (stateParties === "SUCCESS") {
                //03/10/2019: George Galaios: If state success, get the returned List
                var returnValue = response.getReturnValue();
                returnValue.forEach(function(record) {
                record.linkName = 'mydomainLink/'+record.CRMCustId+'/view';
            });
                //ggalaios 2019-10-08 Assign the list of Parties to the Component item
                component.set("v.data", returnValue); 
                component.set("v.spinner", false);
            } else if (stateParties == "INCOMPLETE") {
                //03/10/2019: George Galaios: If state incomplete, show message related to Internet connection
                component.set("v.spinner", false);
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Oops!",
                    "message": "No internet connection.",
                    type: "warning"
                });
                toastEvent.fire();

            } else if (stateParties == "ERROR") {
                //03/10/2019: George Galaios: If case of Error, return the respective message
                component.set("v.spinner", false);
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    "title": "Error!",
                    "message": "Please contact your administrator",
                    type: "error"
                });
                toastEvent.fire();
            }
        });
        $A.enqueueAction(parties);  
    },
})
1

I was going to suggest column type url, but since this behaviour isn't wanted you can use lightning:navigation and see if you can format your columns with this behavior.

({
    handleClick: function(cmp, event, helper) {
        var navService = cmp.find("navService");
        // Uses the pageReference definition in the init handler
        var pageReference = cmp.get("v.pageReference");
        event.preventDefault();
        navService.navigate(pageReference);
    }
})
0

Finally solved my issue by making a few changes... instead of target: _blank i used _self. and in record.linkName ='/lightning/r/'+record.CRMCustId+'/view';

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.