[Sorting] flex and datagrid numerical column sorting

Source: Internet
Author: User
In the past few days, I encountered a problem. The data obtained from the database was converted into an ArrayCollection and bound to the datagrid. As a result, when I clicked the id header, I did not sort the data from small to large, sort by the string ascii code, and then ask ks, the solution found on javaeye needs to customize a sorting method, and then call it, on my computer has been applied successfully, now put this sort out, send out, with link address: http://i5land.javaeye.com/blog/301574
Code of the custom sorting method: 1 public function sortcompare (obj1: Object, obj2: Object): int {
2 var num1: Number = Number (obj1.id. toString ());
3 var num2: Number = Number (obj2.id. toString ());
4 if (num1> num2 ){
5 return 1;
6} else if (num1 <num2 ){
7 return-1;
8} else {
9 return 0;
10}
11}

Then, you only need to change this attribute on the column where you want to redefine the sorting method: sortCompareFunction = "sortcompare"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.