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
Shruti VishShruti Vish 

ui:inputselection i m trying to sort the values

 <aura:attribute name="ideas" type="Idea[]" />
<ui:inputSelect class=" slds-float--left" label="Sort : " aura:id="selection" change="{!c.onChangeFunction}">
                <ui:inputSelectOption text="Trending" label="Trending" value="true" />
                <ui:inputSelectOption text="Popular" label="Popular"/>
                <ui:inputSelectOption text="Recent" label="Recent"/>
            </ui:inputSelect>

 onChangeFunction : function(cmp,event){
      var selected = cmp.find("selection").get("v.value");
   //onsole.log(selected);    
        if(selected=='Recent')
        {
             console.log('hi');
           var action = cmp.get("c.getIdea1");
            action.setCallback(this,function(response){
                if (response.getState() === "SUCCESS"){
                    alert('sqsq');
                    cmp.set("{!v.ideas}",response.getReturnValue());
                }
            }
        ); 
        }
    }

  @AuraEnabled
    public static List<Idea> getIdea1(){
        List<Idea> i=[SELECT Id, Title, Body, CreatedDate FROM Idea order by CreatedDate desc];
        System.debug('hi'+i);
        return [SELECT Id, Title, Body, CreatedDate FROM Idea order by CreatedDate desc];
    }

This is my above code but sort is not happening?
Best Answer chosen by Shruti Vish
Prithviraj_ChavanPrithviraj_Chavan
Hi Shradha,
({
    onChangeFunction : function(cmp,event){
        debugger;
        var selected = cmp.find("selection").get("v.value");
        //onsole.log(selected);    
        if(selected=='Recent')
        {
            console.log('hi');
            var action = cmp.get("c.getIdea1");
            action.setCallback(this,function(response){
                if (response.getState() === "SUCCESS"){
                    alert('sqsq');
                    cmp.set("{!v.ideas}",response.getReturnValue());
                }
            }
                              );
            $A.enqueueAction(action);
        }
    }
})

you just need to add  $A.enqueueAction(action);
nd it will work perfectly please select as best answer if it helped you

All Answers

Prithviraj_ChavanPrithviraj_Chavan
Hi Shradha,
({
    onChangeFunction : function(cmp,event){
        debugger;
        var selected = cmp.find("selection").get("v.value");
        //onsole.log(selected);    
        if(selected=='Recent')
        {
            console.log('hi');
            var action = cmp.get("c.getIdea1");
            action.setCallback(this,function(response){
                if (response.getState() === "SUCCESS"){
                    alert('sqsq');
                    cmp.set("{!v.ideas}",response.getReturnValue());
                }
            }
                              );
            $A.enqueueAction(action);
        }
    }
})

you just need to add  $A.enqueueAction(action);
nd it will work perfectly please select as best answer if it helped you
This was selected as the best answer
Shruti VishShruti Vish
Thanks alot it worked