data type detection should ignore surrounding whitespace

data type detection should ignore surrounding whitespace

jnm99jnm99 Posts: 10Questions: 0Answers: 0
edited July 2010 in Bug reports
Hi Allan,

element sometimes have surrounding whitespace aorund the contents, so one can have a column like

Because of the spaces the type is not detected as numeric so sType needs to be overridden, which (in my case, where this was the only reason for aoColumns, combined with changing the table often lead to other errors when ommitting to keep them in sync) makes things more complex.

I suggest that surrounding whitespace be ignored, as it is the case of template-based html generation quite frequently added by designers who are used to the fact that it has no effect on the layout of the html.

This small patch made this work for me - it applies to all types not just numeric, ( I had to explicitly state date stype as well)


diff --git a/report_web/static/js/jquery.dataTables.js b/report_web/static/js/jquery.dataTables.js
index 29d9e5d..b2fdfe8 100644
--- a/report_web/static/js/jquery.dataTables.js
+++ b/report_web/static/js/jquery.dataTables.js
@@ -5066,7 +5066,7 @@

for ( var i=0 ; i


  • allanallan Posts: 57,300Questions: 1Answers: 9,127 Site admin
    Hi jnm99,

    Thanks very much for the suggestion and diff. I've held off from doing this because it feels too much like altering the input data - however, I agree that DataTables has now reached the point in maturity where this should most certainly be done. I will try to include this functionality in the next beta of 1.7.

  • AlanWAlanW Posts: 1Questions: 0Answers: 0
    Hello Allan
    Firstly you should rightly be very proud of a truly great program with such extensive thought and effort behind it.
    I have started a website from which I have received not a cent yet, but when it is generating I shall be very glad to pass a donation to you as your tables are integral to it's design (& I hope success).

    I have a similar problem in that my numeric columns are not recognised as numeric. They need to have a preceeding '$' currency sign, so that the multiple currency conversion software will work. So 'out of the box' that column is sorted as a text column (eg $1, $100, $2, $200, etc). I have tried the aoColumns feature but it does something weird only sorting the first row. eg
    $("#nz_tours_list").dataTable({"oLanguage":{"sUrl": ""}, 'iDisplayLength': 100,"aaSorting": [[1,'asc']], "bSortClasses": false, "asStripClasses":[], "aoColumns": [null, null, null, { "sType": "numeric" }, null, null]
    Also tried `{ "sSortDataType": "dom-text", "sType": "numeric" },` in place of sType above. If a demo makes anything more clear for you look at (note I may have to put it back to a 'working table' before you look at this).
    Hoping this is not gobbledy gook to you.
    Regards, Alan W.
  • allanallan Posts: 57,300Questions: 1Answers: 9,127 Site admin
    Hi Alan,

    Have you looked at using the currency sorting plug-in: ? Your data is being treated as a string since '$' is not a numeric character - thus the internal data types aren't picking up on it. The currency plug-in will help. There is also a type detection plug-in for the currency type which means you don't need to specify aoColumns - it will be picked up automatically:

    Note that this will pick up strings like '$10' and '£20' - it will not pick up on 'GB £10' etc - which I see on your site at the moment. To address this, you can either customise the sorting plug-ins to your needs, or perhaps use something like the hidden title numeric sorting plug-in:

    Thanks for your kind words about my project, and good luck with your new site :-)

This discussion has been closed.