angular.js sorting doesn't work

Asked 2 years ago, Updated 2 years ago, 116 views

Set to sort values (in descending and ascending order) using angular.js, and
I stumbled.

Below is the page where the problem is occurring.
http://testdayo.chottu.net/

Click
Sort
in the first column of the table. The items are sorted in ascending and descending order.

It is sorted only by the highest digit.

(5,400, 4,950, 980, 980, 500) and
(980, 980, 500, 5400, 4,950).

I think it is recognized as a character, not an integer value.

What is the cause and how should I set it up to resolve the problem?
Please give me advice on where to check and how to solve it.

angularjs

2022-09-30 20:58

1 Answers

After retrieving the JSON data, convert it to a numeric type.

for(vari=0;i<jsondata.length;i++){
    jsondata[i].result_dha_price1 = parseFloat(jsondata[i].result_dha_price1);
    jsondata[i].result_dha_price2=parseFloat(jsondata[i].result_dha_price2);
    jsondata[i].result_dha_amount1 = parseFloat(jsondata[i].result_dha_amount1);
    jsondata[i].result_dha_amount2=parseFloat(jsondata[i].result_dha_amount2);
  }

Remove the "|number" of the sorting ng-click.

<th>Charges A&nbsp;<a href="ng-click="sort_data='+result_dha_price1';reverse=!reverse">Sort>/a>>
<th>Charges B&nbsp;<a href="ng-click="sort_data='+result_dha_price2';reverse=!reverse">Sort </a><th>


2022-09-30 20:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.