chifailai2 / jquery-datatables-column-filter

Automatically exported from code.google.com/p/jquery-datatables-column-filter
0 stars 0 forks source link

Null dates in date-range columns causes "Uncaught Invalid arguments" error on filter or sort #28

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Make table containing a column with date data
2. Populate with data, some of which has a null
3. Filter/sort the date column
4. Observe "Uncaught Invalid arguments" error

What version of the product are you using? On what operating system?
Heavily patched 1.2.1

Please provide any additional information below.
I narrowed the problem down to this:

                var dCellDate = $.datepicker.parseDate($.datepicker.regional[""].dateFormat, aData[index]);

When aData[index] is null value, the above mentioned error is thrown. 
Extracting just that line allowed me to test a few things and I have observed 
the following:
- Null value: Uncaught Invalid arguments
- 0000-00-00: Uncaught Invalid date (When pulling dates from MySQL)
- 0001-01-01: Parses without error but is incorrectly parsed as 2001-01-01

When trying to fix this by setting null dates to "", I rediscovered Issue 21. 
All rows containing null dates then dissapear. The only solution I have found 
so far is to set null or empty dates to a valid date string, ie: 1111-11-11
Quick note that 0001-01-01 incorrectly gets parsed as 2001, 1001-01-01  parses 
correctly however.
My present solution is this:

                    // We must take into account null dates, empty dates and "zero" MySQL dates
                    if (aData[index] == null || aData[index] == "0000-00-00" || aData[index] == "") {
                        aData[index] = "1111-11-11";
                    }
                var dCellDate = $.datepicker.parseDate($.datepicker.regional[""].dateFormat, aData[index]);

This also solves Issue 21 but is a rather ugly hack. As long as you do not have 
dates prior to whatever you are using as your alternative to 
0000-00-00/null/empty dates, you should be fine. You also have to accept that 
null/empty dates are then treated in sorting as your "oldest" date.

I apologize for the lack of diff format but I have so many changes done to 
vanilla 1.2.1 that are from various bug fixes or added functionality that it 
would be futile.

Original issue reported on code.google.com by g.duerrm...@gmail.com on 21 Aug 2011 at 4:12

GoogleCodeExporter commented 8 years ago

Original comment by joc...@gmail.com on 24 Sep 2011 at 10:39

GoogleCodeExporter commented 8 years ago
Hi,

Could you please try with the latest version 1.2.2? I have fixed issue with 
filtering however I don't know what to do with the wrongly parsed date 
0001-01-01. It seems to me that this is general bug with the date picker parse 
date function, so is there a change to use exactly 2001 format?

Thanks,
Jovan

Original comment by joc...@gmail.com on 24 Sep 2011 at 10:55