A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Datagrid sort by number

  1. #1
    Bob (the singing sock)
    Join Date
    Aug 2000
    Location
    Århus, Denmark
    Posts
    472

    Datagrid sort by number

    Hi all,

    When pressing a header in the datagrid the datagrid is sorted alphabetically.
    Is there any way to make it sort numerical instead?

    Any thoughts?
    //pod

  2. #2
    Senior Member
    Join Date
    Jan 2003
    Posts
    106
    Anyone figured this out? That is, how to sort a column of numbers in a datagrid? (v2 Component)

  3. #3
    Bob (the singing sock)
    Join Date
    Aug 2000
    Location
    Århus, Denmark
    Posts
    472
    Sorry no one replied and i didn't figure it

    //pod

  4. #4
    Senior Member
    Join Date
    Jan 2003
    Posts
    106
    Alright. Looks like we'll just have to figure it out on our own:


    Code:
    //custom sorting functions for the ranking column
    // replace "ColumnName" with the name of the column you want to sort
    // in this case, my column was located at columnIndex 2, adjust to suit your needs
    
    
    function sortNumericASC(a, b) {
      return Number(a.ColumnName) > Number(b.ColumnName);
    }
    function sortNumericDESC(a, b) {
      return Number(a.ColumnName) < Number(b.ColumnName);
    }
    var headerListener = new Object();
    headerListener.headerRelease = function(event){
      trace("column header num. "+event.columnIndex+" was pressed");
      if (event.columnIndex == 2){
        if(sortASC == NULL){
           sortASC = true;
        }else{
           sortASC = !sortASC;
        }
        if(sortASC){
           my_dg.sortItems(sortNumericASC);
        }else{
           my_dg.sortItems(sortNumericDESC);
        }
      }
    };
    my_dg.addEventListener("headerRelease", headerListener);
    Cheers,
    John
    Last edited by jvanv8; 08-16-2004 at 11:39 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center