Possible bug in auto type detection - 1.9.3
Possible bug in auto type detection - 1.9.3
jerryb
Posts: 2Questions: 0Answers: 0
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".
Using version 1.9.3, line 11948:
sData = "$170.10";
var iParse = Date.parse(sData);
iParse is valid and set to "-56778865200000".
This discussion has been closed.
Replies
There is a matching type detection plug-in as well: http://datatables.net/plug-ins/type-detection#currency
Allan
[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.
Thanks for the updates on how you got in with it!
Allan