Table Sorting Function - Custom Key

Discussion in 'JavaScript' started by mnymkr, Jun 2, 2007.

  1. #1
    I was looking at some javascript and AJAX examples for table sorting as opposed to sorting a huge db by php.

    The biggest problem is that I need a custom key for a column that does not sort alphanumerically.

    Considering the object nature of JQuery and other AJAX apps, would this be possible to assign a class to just one table header with a custom key for sorting?
     
    mnymkr, Jun 2, 2007 IP
  2. immortalus

    immortalus Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why not creating a compare function and using it?
    I'm not very good at JS, but if it's anything like C it should have function pointers...

    Just make a sorting function that gets a pointer to a compare function which would return -1, 0, 1 respectively for (a<b), (a==b), (a>b)
    And then use that compare function to sort...
     
    immortalus, Jun 2, 2007 IP
  3. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #3
    I'm using the sorttable library. It's very easy to use, because it automatically detects each column sorting method. But for your custom sorting function you need to use their "Using custom sort keys" feature.
     
    ajsa52, Jun 2, 2007 IP
  4. mnymkr

    mnymkr Well-Known Member

    Messages:
    2,328
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    120
    #4
    I couldn't get the above to work with a sql generated paginated table.
     
    mnymkr, Jun 3, 2007 IP