Sorting by column based on span value

Sorting by column based on span value

flipboxflipbox Posts: 2Questions: 0Answers: 0
edited February 2010 in General
DataTables Rocks!

I'm stumped. I'm looking to sort my table based on data that isn't displayed or is formatted in a manner that isn't easily sortable as it's displayed. My initial thought is to dedicate a hidden column to hold this information and I could organize the data in span tags with a class that will elude to the data type. I see in the API docs the fnSort function will sort based on a column, but is it possible to sort the first column based on the contents of a span with the class of "entry_date"?

I understand I could create individual columns for each sortable data set, but I would like to reduce the amount of unneeded markup.

Thanks in advance.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Do you mean something like this: http://datatables.net/plug-ins/sorting#hidden_title_string . It will sort based on the 'title' attribute of 'there'?

    Allan
  • flipboxflipbox Posts: 2Questions: 0Answers: 0
    Close. I saw the numeric title sorting (which is similar to your link), but what I was envisioning works in reverse. Here is an example of a row.

    [code]

    3
    3
    4

    [/code]

    I'm looking to sort based on the value of all span's with the class "rating_overall"...or sort based on the class "rating_technical". I'm not sure if this is an acceptable method or if it would be easier to create individual columns for each and pass the column number.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Oh I see - interesting! It's certainly possible using a custom sorting plug-in, like the one I linked to above. There isn't one available which would do this already - but there are plenty which you can use as a basis. As you note, the alternative is to split them into columns. The later is more conventional - but either should work.

    Regards,
    Allan
This discussion has been closed.