I have a custom object called event and it houses the events for a non-profit I am working for. I am trying to find a way to get the events to be sorted alphabetically when the page is pulled up. I am iterating over a list and grabbing each event to be displayed, so does there need to be some sort of recursive step in my code? Any help is greatly appreciated. :)
I am fairly new to Salesforce, so I apologize if this can be answered very easily, but I have yet to find anything online through my research.
Here's my event class:
public class eventClass {
@AuraEnabled
public static List<Event__c> getEvents() {
return [Select Id, Name From Event__c];
}}
Here's my event component:
<aura:component controller="eventClass">
<aura:handler name="init" action="{!c.myAction}" value="{!this}" />
<aura:attribute name="events" type="Event[]" />
<ul>
<h1>Choose an Event</h1>
<aura:iteration items="{!v.events}" var="event">
<li class="minli"> <ui:outputText value="{!event.Name}"
class="eventName"></ui:outputText> <ui:button label="Select"
class="eventSelect" press="{!c.eventSelect}"></ui:button> </li>
</aura:iteration>
</ul>
</aura:component>
And lastly, my component controller:
({
myAction : function(component, event, helper) {
var action = component.get("c.getEvents");
action.setCallback(this, function(data) {
component.set("v.events", data.getReturnValue());
});
$A.enqueueAction(action);}})