Opera...
Opera...
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
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
This discussion has been closed.
Replies
It works perfteclt in FF & IE, but in Opera it displays (sorts) as above...
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
$('#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
Changing sType seemed to do the trick...
Thanks for that for just now!
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
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
Allan
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?
I still have that "sType": "html" for the date columns...
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
how would I go about that method *nudge* *nudge*... (being lazy here! No tto mention trying to finsh off lots of other stuff! :) )
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
Cheers.