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
Sumesh ChandranSumesh Chandran 

Filtering from the initial items of the array before the filtering

Here in this code below I have an opportunities array. When I click on diffferent tabs of the component the array should get filtered with the appropriate selection of the tab. When the page loads, clicking on the first tab loads the right data, but clicking on another one returns an empty list. I know the original items of the array will get overwritten when you click on the second tab. How do I do the filtering from the original items of the array? How do I go about coding that?. New to programming.

Please advise!
tabSelect: function (component, event, helper) {
        var sup = component.get("v.selTabId");
        let oppsAll = component.get("v.opps");            
        let oppsbySup = oppsAll.filter(x => { 
            return x.sumchans__Owner_Manager__c === sup;
        });       
        component.set("v.opps", oppsbySup);
    }
Best Answer chosen by Sumesh Chandran
Sampath SuranjiSampath Suranji
Hi,
I suggest you to use an another attribute to store the default values of opportunities. Then your code looks something like below,
 
//your default attribute
<aura:attribute name="defaultOpp" type="list"/>
//if you have a function to bind opportunities, then bind values to 'defaultOpp' at the initial page load
// your tabSelect function looks like below
var sup = component.get("v.selTabId");
        let oppsAll = component.get("v.defaultOpp");            
        let oppsbySup = oppsAll.filter(x => { 
            return x.sumchans__Owner_Manager__c === sup;
        });       
        component.set("v.opps", oppsbySup);

regards
Sampath

All Answers

Sampath SuranjiSampath Suranji
Hi,
I suggest you to use an another attribute to store the default values of opportunities. Then your code looks something like below,
 
//your default attribute
<aura:attribute name="defaultOpp" type="list"/>
//if you have a function to bind opportunities, then bind values to 'defaultOpp' at the initial page load
// your tabSelect function looks like below
var sup = component.get("v.selTabId");
        let oppsAll = component.get("v.defaultOpp");            
        let oppsbySup = oppsAll.filter(x => { 
            return x.sumchans__Owner_Manager__c === sup;
        });       
        component.set("v.opps", oppsbySup);

regards
Sampath
This was selected as the best answer
Sumesh ChandranSumesh Chandran
Thanks Sampath. I was able to figure it out.