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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -