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

problem in filtering records on lightning component

public with sharing class bOQrenewClass {
    public static List<WrapperClass> getproducts(String productToSearch) {
        List<WrapperClass> wrapperList = new List<WrapperClass>();
		Map<String, List<SelectedRecordsModel>> stageMap = new Map<String, List<SelectedRecordsModel>>();               
        String newSearchText = '%'+productToSearch+'%';
        for(Product2 obj: [SELECT Id, Name, Quantity__c, total_amount__c, Price__c, Section__c FROM Product2 ]){//WHERE Name LIKE :newSearchText
            stageMap.put(obj.Section__c, null);           
        for(Product2 obj: [SELECT Id, Name, Quantity__c, Price__c, total_amount__c, Section__c FROM Product2  ORDER BY Section__c ASC, Name ASC]) {   //WHERE Name LIKE :newSearchText                   
            List<SelectedRecordsModel> prodList = new List<SelectedRecordsModel>();
            if (stageMap.get(obj.Section__c) != null) {
                prodList = stageMap.get(obj.Section__c);
            prodList.add(new SelectedRecordsModel(obj));      
            stageMap.put(obj.Section__c, prodList);
        for(String obj: stageMap.keyset()){
            WrapperClass wrapperObj = new WrapperClass();
            wrapperObj.Stage = obj;
            wrapperObj.productRenewList = stageMap.get(obj);
        return wrapperList;
        public class WrapperClass {
        @AuraEnabled String Stage{get; set;}
        @AuraEnabled List<SelectedRecordsModel> productRenewList {get; set;}
    public class SelectedRecordsModel {
        @AuraEnabled Boolean isSelected {get;set;}
        @AuraEnabled Product2 prd {get;set;}
        public SelectedRecordsModel(Product2 prd){
            this.prd = prd;
            isSelected = false;

component code
 <ui:inputText class="slds-input slds-size_4-of-12 slds-border_bottom " aura:id="search" placeholder="Type to search"
                  keyup="{!c.filterContacts1}" />

<aura:iteration items="{!v.newWrapperList}" var="obj" indexVar="i">                
            <tr class="slds-box slds-theme_shade ">
                <td colspan="5">
                    <lightning:formattedText value="{!obj.Stage}"/>
                <aura:iteration items="{!obj.productRenewList}" var="iobj" indexVar="j" start="0">
                    <tr class="html" >                           
                        <td >
                            <ui:inputCheckbox value="{!iobj.isSelected}" change="{!c.pushToList}" name="{!i+''+j}" />
                            <ui:outputText  value="{!iobj.prd.Name}" />
                            <lightning:input readonly="true" class="input-box slds-no-focus" style="border:none!important;" type="Number" value="{!iobj.prd.Price__c}"  />
                            <!-- <span onkeyup="{!c.performCalculation}">-->
                            <lightning:input class="input-box" type="Number" min="0" value="{!iobj.prd.Quantity__c}" onchange="{!c.performCalculation}" />
                            <!-- </span>-->
                            <lightning:input readonly="true" class="input-box slds-no-focus" style="border:none!important;" type="Number" value="{!iobj.prd.Total_Amount__c}"   />

js controller code 
filterContacts1 : function(component, event, helper){
        console.log("@@ "+ JSON.stringify(arr));*/
        var arr = new Array();
        var searchKey = component.get("v.productToSearch").toLowerCase();
        var allRecords = component.get("v.wrapperList");
        for(var i =0; i<allRecords.length;i++){
            var obj = allRecords[i];
            for(var j=0; j<allRecords[i].productRenewList.length;j++){
                var str = allRecords[i].productRenewList[j].prd.Name;
       // cmp.set("v.wrapperList",cmp.get("v.newWrapperList"));
as the code above, i have one apex, lightning component and js controller. I have properly bind that wrapper list to the component 
now the requirement is that i hve to place a filter record box in which i need to enter name of the product on keyup but there are some mistake i am edoing that on pressing the backspace key the records are again adding to list and the duplicates are showing on outpuut 
please help 

if you have any query you can comment
Thanks in advance