component.set("v.Accounts", Accounts);
has the accounts that I need.
<th scope="col">
<div class="slds-truncate" title="Opportunity Name" onclick"{!sortbyOpportunityNAme}">Opportunity Name</div>
</th>
I was wondering if there is anyway that I could sort the results on the client side instead of making server calls on click of the column
Best Answer
Edit
Here's an updated link for the code provided below.
In Lightning, there's no need to import a library or call out to the server, you can just write your own. Note: I've not tested this, so you may need to tweak it to suit your needs.
Your actual click handler needs a minor adjustment as well:
This code assumes two variables, namely sortAsc, a Boolean, and records, a list of Opportunity records.
To make it more palatable for multiple fields to sort by, you'll want to put this logic into a helper function, then you can replace all the .Name references with a dynamic attribute, like
a[field] < b[field]
.I actually wrote a demo for this. It's not "pretty", but it demonstrates the functionality:
OpportunityHelper.cls
opportunity.app
opportunityController.js
opportunityHelper.js