I found that sorting is wrong for numbers and dates. I think this is because views template adds several spaces after the value, and DataTables thinks that it is text. This can be solved by editing template datatables-view.tpl.php, making td part on one line:
<td class="views-field views-field-<?php print $fields[$field]; ?>"><?php print $content; ?></td>
Comments
Comment #1
duellj commentedI've added basic column type detection in the next dev release. There's still a problem with some date formats, most notably the default Drupal date format (Monday, June 28, 2010 - 18:35). But number sorting should work now. Let me know if it fixes your problems.
Thanks for your bug reports, very helpful!
Comment #2
dpopov commentedI'm afraid, it's not.
If template is not changed than sorting is wrong for numbers and dates. If template is changed than sorting is OK for numbers, sorting for dates depends on date format and browser.
Date format 2010.07.30
Chrome – OK
IE8, Firefox, Opera, Safari – wrong (opposite) ascending/descending
Date format 30.07.10 04:58
Opera – OK
IE8, Firefox, Safari – wrong (opposite) ascending/descending
Chrome – wrong
Comment #3
duellj commentedWhat are field are you using for your numbers field? Is it a plain integer, float, contain html?
Comment #4
dpopov commentedYes, there was html – I was using 'Link this field to its node' option. Without it number sorting is correct with unmodified template.
Is it possible to detect field type by displayed value? Using 'Link this field to its node' option is very common and sometimes other html is needed.
Comment #5
westie commentedI am having problems with the default sort on dates, using 6.x 1.0. Kinda need this functionality otherwise the Data tables is pretty awesome.
Just checking if you have seen : http://www.datatables.net/plug-ins/sorting#functions_type - Date (dd/mm/YYY hh:ii:ss) and do you have any eta on next release to address stable as per above dev version.
Comment #6
sachbearbeiter commentedsubscribe
Comment #7
duellj commentedFocusing this issue on date sorting.
Comment #8
dsrikanth commentedWould love to hear any update on this.
Comment #9
eule commentedsorting is not working in a view for me! the issue is from 2010! who please is the quality of the Modules? i only read from the quality ...mostly are not working in the right way! ..but if u will give a working module to the community u will stopped for weeks / months ...after all this is not good for the community! trying wordpress instead ..things i want work on wordpress mutch better. good luck with d8
this is nothing about the datatables module coder! thanks for your time. its about the drupal organisation
anyway please fix that bug with numbers and dates
Comment #10
eule commentedComment #11
bluetegu commentedThis can be fixed without code by defining date format which is supported by Datatables and check the 'Strip HTML tags' option in rewrite section of the date field view settings. See http://bluetegu.net/node/13
Comment #12
ey commented@bluetegu, what you suggest is not a fix but maybe a workaround. I have a date field with "d.m.Y" format which in Germany a standard way of writing dates and I want to be able to sort my date column without changing the date format.
Comment #13
jeebsuk commentedAdding myself to the pile of people who'd like to see a proper fix for this if it's possible.
Comment #15
jeebsuk commentedThe timestamp on that commit appears to be "July 30, 2010 3:39" - which might explain why a new dev version of the module hasn't rolled. Some kind of d.o gremlins?
Comment #16
jasonflaherty commentedFollowing this...
Comment #17
dqdWe are on 7.x 2.x so I would say this issue can be closed for now and reopened with changed code version option if somebody wants to report it for 2.x.
Comment #18
no_idea_yet commentedBit late to the party by 9.5 years but has anyone got a fix for this? Sorting by date has to be one of the most used functions I would have thought; works fine in views as a normal table ... totally dead with DataTables from the looks of it.
Spent the best part of the last 24 hours trying to figure it out but sadly I'm not that fluent in "geek" so 75% of the time I have no idea what I'm looking at :)
This datatables plugin (https://datatables.net/blog/2014-12-18) seems to fix the issue but I have no idea how to implement it. I installed the Drupal Header and Footer Scripts plugin (https://www.drupal.org/project/header_and_footer_scripts) and then added to two refrences to the CDN based scripts mentioned but ... what next?
Any pointers as to how to fix this issue would be much appreciated.
Comment #19
dqdThanks for your report, #18. But please do not misuse the Priority level to bump. Descriptions of the Priority and Status values can be found in the Issue queue handbook.
Library implementation modules have usually a more "partly" maintaining cycle and if issues stay open for a long time, it is often based on the fact that not enough users hit that corner, useful reports are missing and/or noone tried to provide a patch. Or there is actually no issue but a user error (not rare).
All I can say now from a short glimpse is that I wonder why it works in Drupal 8 version then (same lib version)? Are you sure you have tested enough and have formatted date correctly so that sorting can be acheaved successfully? We need more detailed reports on this and how users use date etc to really get forward. That's the main reason why this issue was open so long.
And from reading #2:
I would say users expect the module to fix things the module can't fix since such things depend on the theme and how numbers and dates are rendered by site builders.
Comment #20
dqdAdditionally to my last comment I would like to add a concern: We should not accept such negative and contra productive comments like made by @eule in #9 without enlighting the user to how things work to the better. Apart from that the users profile obviously indicates (missing) will to contribute to any Drupal community project, which is ok, because it is up to anybody how to play with Drupal and how to be committed to the project, or not. But I would like to make a few suggestions regarding the actual issue behind such comments: some users still seem to think that you can simply make a respectless complain if something is not working like expected out of the box on a free available large Open Source project without getting critisized for such a comment and wihtout showing own will to help? A Drupal contrib module is community work and the user did not add any useful help to solve issues but complains about parts not working, even it it turns out to be user input error. If this is the way the person goes thru life I hope that not too much people depend on this person.
Again, sorting by date depends on many things not in scope of this project depending on how dates get rendered for sorting.
Due to upcoming EOL of Drupal 7 I set it to Closed. Thanks for taking the time to report and all the work on this! Read more about here: https://www.drupal.org/about/drupal-7/d7eol/partners
Feel free to open a new issue with a proper report and patch to solve the issue if it is in the scope of this project.