Possible bug in auto type detection - 1.9.3

Possible bug in auto type detection - 1.9.3

jerrybjerryb Posts: 2Questions: 0Answers: 0
edited September 2012 in Bug reports
When auto-detecting the date type, certain currency values are returning false positive.

Using version 1.9.3, line 11948:

sData = "$170.10";
var iParse = Date.parse(sData);

iParse is valid and set to "-56778865200000".

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Its a string because it has non-numeric data in it. If you want to currency sort, use the currency sorting plug-in: http://datatables.net/plug-ins/sorting#currency :-)

    There is a matching type detection plug-in as well: http://datatables.net/plug-ins/type-detection#currency

    Allan
  • jerrybjerryb Posts: 2Questions: 0Answers: 0
    edited September 2012
    So I am using the currency matching type detection plug-in. The problem is that the built-in matching type detection matches "$170.10" as "date" type in the following functions:

    [code]
    function (sData) {
    var iParse = Date.parse(sData);
    if ((iParse !== null && !isNaN(iParse)) || (typeof sData === 'string' && sData.length === 0)) {
    return 'date';
    }
    return null;
    }


    function _fnDetectType(sData) {
    var aTypes = DataTable.ext.aTypes;
    var iLen = aTypes.length;

    for (var i = 0; i < iLen; i++) {
    var sType = aTypes[i](sData);
    if (sType !== null) {
    return sType;
    }
    }

    return 'string';
    }
    [/code]

    Because sType is returned once a type is detected, it never gets a chance to enter the currency matching function.

    I was able to get around the issue by adding "&& iParse > 0" in the function as follows:

    [code]
    function (sData) {
    var iParse = Date.parse(sData);
    if ((iParse !== null && !isNaN(iParse) && iParse > 0) || (typeof sData === 'string' && sData.length === 0)) {
    return 'date';
    }
    return null;
    }
    [/code]


    But others may run into issues doing that if they're using dates before 1970.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Humrugh - yup - that's horrific. Sorry about that :-(. The type detection in DataTables badly needs an overhaul. The real trouble with it is keeping it fast, while also through. I think at the moment its just not complete enough and I need to come up with something better, although it will likely impact performance (I'll try to keep it to an absolute minimum!).

    Thanks for the updates on how you got in with it!

    Allan
This discussion has been closed.