Created
          September 21, 2017 01:40 
        
      - 
      
- 
        Save karanrajs/a9621dfcce45c2f9048efac8b4dd3ec5 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | sortData: function (cmp, fieldName, sortDirection) { | |
| var data = cmp.get("v.mydata"); | |
| var reverse = sortDirection !== 'asc'; | |
| data.sort(this.sortBy(fieldName, reverse)) | |
| cmp.set("v.mydata", data); | |
| }, | |
| sortBy: function (field, reverse, primer) { | |
| var key = primer ? | |
| function(x) {return primer(x[field])} : | |
| function(x) {return x[field]}; | |
| reverse = !reverse ? 1 : -1; | |
| return function (a, b) { | |
| return a = key(a), b = key(b), reverse * ((a > b) - (b > a)); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment