0

I have a Search Order Lightning Component that has a button that will open again the Lightning Component in a new subtab but upon opening the component I want to fetch the values and still display the result in the subtab. Is it possible?

Thank you.

enter image description here

1

When you are talking about subtab you mean subtab in lightning console? If yes, that's possible quite easily.

Youre component needs to be url addressable so it can be opened by workspace api:

<aura:component description="MyComponent" implements="lightning:isUrlAddressable">

Your main component needs to have workspace api included

<lightning:workspaceAPI aura:id="workspace"/>

And data from main component can be passed using page reference state

openSubTab : function(component, event, helper) {
var workspaceAPI = component.find("workspace");
    workspaceAPI.openSubtab({
        pageReference: {
            "parentTabId": //parentTabId//,
            "type": "standard__component",
            "attributes": {
                "componentName": "c__MyComponent"  // c__<comp Name>
            },
            "state": {
                "c__name": component.get("v.myName") // c__<comp attribute Name>
            }
        },
        focus: true
    }).then((response) => {
           workspaceAPI.setTabLabel({
              tabId: response,
              label: "App Name / Tab name"
           });
    }).catch(function(error) {
        console.log(error);
    });
}

Please note that parentTabId is required and can be aquired by using for example getTabInfo() from WorkspaceAPI

| improve this answer | |
  • Hi @user1974566 does this mean I can't use only one component for this scenario? – Atoc Aug 4 at 7:16
  • 1
    Hmm it would be probably possible (send additional parameter which would control what is displayed) but first of all you'll still need to pass arguments in state second of all: it would be rather bad design. Ultimately it's better idea to divide components per funcionality (follow same single responsibility rule like in object oriented programming) – user1974566 Aug 4 at 7:29
  • Actually I've already done the code you posted sorry I forgot to mention. I'll try to check the (send additional parameter which would control what is displayed) since what I'm lacking is when I click on the open table button the data displayed in the table still needs be displayed in the subtab. Note to be checked: both component and the button that's opening the subtab is in 1 component (probably a bad design) Thank you. – Atoc Aug 4 at 7:53

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.