Opera...

Opera...

brianmmbrianmm Posts: 41Questions: 0Answers: 0
edited May 2009 in General
Hi.. not sure if this is a problem or not...

I have the following table, I have set it to sort on the End Time column, it seesm to sort it by the time part and not the date?

End Time Method Status
03May09 23:28 SetParameterValues 9003
01May09 23:25 GetParameterValues 9005
01May09 23:23 GetParameterValues 0
03May09 23:22 SetParameterValues 9003
01May09 23:20 GetParameterValues 0
03May09 22:50 SetParameterValues 8801
03May09 22:41 SetParameterValues 8801
01May09 22:14 GetParameterValues 0
01May09 22:09 GetParameterValues 0
01May09 22:05

Replies

  • brianmmbrianmm Posts: 41Questions: 0Answers: 0
    Sorry...

    It works perfteclt in FF & IE, but in Opera it displays (sorts) as above...
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I would have said that the problem was that Opera wasn't picking up the End column as a date (you'll need to use a plug-in date sorting function) - see for example http://datatables.net/forums/comments.php?DiscussionID=122#Item_8 .

    However, it looks like the sorting is almost completely random - I don't see any logic at all in it. Do you have some HTML in that column? If so it will also be sorting the HTML - you need to set the column type (sType) to 'html' to sort without the HTML tags being taken into account.

    Purely out of interest - your output looks rather TR-069 like... Is this an area you are working in?

    Thanks
    Allan
  • brianmmbrianmm Posts: 41Questions: 0Answers: 0
    $(document).ready(function() {
    $('#history').dataTable( {
    "bAutoWidth": false,
    "aaSorting": [[ 1, "desc" ]],
    "aoColumns": [
    null,
    /* End Time */ { "bSortable": true,
    "bSearchable": true },
    /* Method */ { "bSortable": false,
    "bSearchable": true },
    /* Status */ { "bSortable": false,
    "bSearchable": true }
    ]
    } );
    } );



    And here is a snippet of my table:




     
    End Time
    Method
    Status





    01May09 15:32
    GetParameterValues
    8800


    ...

    There is no HTML in there....

    Yes I am developing an ACS (cut down but enough to be usefull!). Contact me privatley if you want to know more.

    Cheers,

    Brian
  • brianmmbrianmm Posts: 41Questions: 0Answers: 0
    Hi Allan,

    Changing sType seemed to do the trick...

    Thanks for that for just now!
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Brian,

    Good to hear you got it working - although as you point out there is no HTML in your date/time column, so I'm a little surprised that it works. Having said that if it works - who am I to complain :-)

    Allan
  • brianmmbrianmm Posts: 41Questions: 0Answers: 0
    actually...

    Sorting is'nt working on the dateformat: 11May09 12:51 when with the sType set to html... so I guess I need to create a function?

    Next Question then :) anyone written a function to do it!!! Lazy and got tons of other stuff to do for this project :P
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Yup - I did think that there was something a little funny going on there. There is quite a reasonable chance that if you just put a little white space into the date format (e.g. 11 May 09 12:51) that it will format correctly. Otherwise, it will be a case of breaking the string into it's component bits and gluing them back together as a simple integer in a custom sorting plug-in function. Give me a shout if you need a hand with that :-)

    Allan
  • brianmmbrianmm Posts: 41Questions: 0Answers: 0
    hello :)

    I need a hand with that!... the other slight problem though is the dateformat is customisable per user as according to php's formatting ... so would doing this potentially break sotring for other date formats?
  • brianmmbrianmm Posts: 41Questions: 0Answers: 0
    changed the format of dates to 21/04/2009 14:06, 21-04-2009 14:06 and their are sorted correctly (in FF or IE)...?

    I still have that "sType": "html" for the date columns...
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Brian,

    When you say it's user definable, do you have a limited number of options, or do you allow them to enter a custom PHP formatting string which will be used for the formatting? If the latter than this method won't really work - there is no way to parse all of those options without knowing what the formatting actually is. However, there is two other ways...

    1.
    Something you could do is to format your output from PHP like this: 'Fri, 13 Feb 2009 23:31' then you can use a custom sorting plug-in to get the title attribute from the span and then sort on that. This is perhaps the more preferable of the two methods.

    2.
    What you can do is add an extra (hidden) column to your table with a unix timestamp representation of your date/time and use that column for the sorting on your visible date column (you can use iDataSort to sort one column based on another: http://datatables.net/usage#iDataSort ).

    The hidden column assumes that your UI requires Javascript (the unix time column would be visible for non-Javascript browsers). If you want to work around this and allow JS and non-JS, you could have the time stamp as an attribute for your date column, and then use JS to pull this data out and insert a new column (which of course will happen only on JS browsers).

    Regarding the change in format working - I think this is just luck :-). If the type is html then DataTables will sort by string only (after html stripping).

    Shout if you want a hand with either method, assuming that this will work for you. Otherwise it's back to looking at date formatting functions :-)
    Allan
  • brianmmbrianmm Posts: 41Questions: 0Answers: 0
    I like the 1st suggestion... So we can take the MySQL DateTime field, make it into a timestamp and shove it in the title of the span?

    how would I go about that method *nudge* *nudge*... (being lazy here! No tto mention trying to finsh off lots of other stuff! :) )
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    First suggestion: Yup - that's the idea.

    Try this:

    [code]
    jQuery.fn.dataTableExt.oSort['title-numeric-asc'] = function(x,y) {
    var x = a.match(/title="(.*?)"/)[1];
    var y = b.match(/title="(.*?)"/)[1];
    x = parseFloat( x );
    y = parseFloat( y );
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    };

    jQuery.fn.dataTableExt.oSort['title-numeric-desc'] = function(x,y) {
    var x = a.match(/title="(.*?)"/)[1];
    var y = b.match(/title="(.*?)"/)[1];
    x = parseFloat( x );
    y = parseFloat( y );
    return ((x < y) ? 1 : ((x > y) ? -1 : 0));
    };
    [/code]

    Warning... I've not fully tested this - but it should work okay across all browsers :-)

    To make DataTables use this sorting function, set the sType to 'title-numeric' for your date column.

    Hope that helps,
    Allan
  • brianmmbrianmm Posts: 41Questions: 0Answers: 0
    OK will try and let ya know :)

    Cheers.
This discussion has been closed.