javascript - AngularJS UI-Grid Sort -


how can sort following data response of ui-grid date

    this.$http.get(url)         .success(data => {             this.$scope.gridoptions.data = data //.slice(firstrow, firstrow + paginationoptions.pagesize);         }).finally(() => { this.$scope.loading = false; this.$scope.loadattempted = true; }); 

i reponse array of objects , 1 of properties of type dob, 1 want sort by.

here goes sample of array

[ {  "name":"john",  "dob" : "12/07/1987" } {  "name":"jack",  "dob" : "12/07/1989" } {  "name":"sara",  "dob" : "12/07/1980" } ] 

thanks,

you can use javascript sort method desired result this.

result = response.sort(function(a, b) {     return new date(a.dob).gettime() - new date(b.dob).gettime() }) 

the result should this.

[   {      "name":"sara",     "dob" : "12/07/1980"   },   {     "name":"john",     "dob" : "12/07/1987"   },   {     "name":"jack",     "dob" : "12/07/1989"   } ] 

you can read more javascript sort method on w3schools.


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -