DataTables only sorting Dates

DataTables only sorting Dates

whobutsbwhobutsb Posts: 15Questions: 0Answers: 0
edited March 2009 in General
Hi All,
I have been playing around with this DataTables plugin which is pretty awesome. I'm running into a issue where I'm trying to sort a list that has the Header Rows: Event Name, Contact Name (First & Last), Event Date, and Event Status, the formats for the tbody rows are : string, string, date, and string. For some reason when I enabled the DataTables it will only allow me sort the Event Dates but none of the other columns. Here is the JS code I'am using:

$('table').dataTable({
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"aaSorting": [[ 2, "desc" ]],
"bInfo": true,
"bAutoWidth": false
});
the aaSorting is sorting the date to start off which I want it to do but, I would like to option to also sort the other columns if necessary.

Has any one else run into a issue similar to this? Thanks for the help!

Replies

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Hi whobutsb,

    Very odd. With defining an initial sorting column, you should certainly still be able to sort on the other ones. One thing to check, is the class "sorting" applied to the other columns? Also, do you have a link you could post showing an example?

    Thanks
    Allan
  • whobutsbwhobutsb Posts: 15Questions: 0Answers: 0
    Hi Allan,
    Thanks for getting back to me. Unforunately I don't have a live copy on the web. The application is currently running on my companies intranet. When you mean "sorting" class do you actually apply a class called sort? Like : ? Do you have a link to the documentation on this.

    I just realized something that I forgot to mention as well. The Event Name and Contact Name cells are links would that make a difference? I also applied this to other tables in my application like my companies table, which has a list of company names the state they are in and the number of events they have held. And still the sorting still seems to default to the integer number of events, and none of the of the other columns will sort.

    Hope maybe i mentioned that sparked an idea for you. Thanks for your help, and thank you making a great plug in!
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Hi whobutsb,

    Each column that can be sorted on should have the TH element in THEAD with the class name "sorting" (this is applied by DataTables automatically) - you can see an example here: http://datatables.net/examples/example_zero_config.html

    I'm not quite sure what you mean by the Event Name and Contact Name cells? DataTables currently only supports one TBODY - could you run your HTML through the w3c validator and check that it parses okay? As you can see from my multi-column sorting example ( http://localhost/datatables/datatables-1.5/example_multi_col_sort.html ) you certainly should be able to define a default sort and then sort on other columns. Your table doesn't have any cospan's in it does it? Or are you seeing any Javascript errors? It really would be helpful if you could put a stripped down example somewhere on the web.

    Thanks,
    Allan
  • whobutsbwhobutsb Posts: 15Questions: 0Answers: 0
    Good Morning Allan,
    I just took a look a the source of the table and dataTables is definitely applying the "sorting" class to the tags. Here is a selection from the source:


    Search:



    Event Name
    Contact Name
    Event Start Date
    Current Status




    7-24-09 RHD
    Karen Pritchard
    Jul 9 2024 6:00PM
    Cancelled


    Cheng Rehearsal Dinner
    Shirley Cheng
    Sep 4 2010 12:00AM
    Prospective


    Parness/Musco Rehearsal Dinner
    Paige Musco
    Jul 9 2010 5:00PM
    Cancelled
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Hi whobutsb,

    The table HTML looks good - thanks for posting it! I do notice that you have HTML inside your cells though - with the default sorting, the HTML (as a string) will also be sorted on. This can be overcome by using the sType of 'html' of the columns which have HTML in them (or are you already doing this?). An example of this can be seen here: http://datatables.net/examples/example_html_sort.html

    Allan
  • whobutsbwhobutsb Posts: 15Questions: 0Answers: 0
    That was it!!! Thank you very much for your help! Its working perfectly now.
This discussion has been closed.