Quantcast
Channel: Free community support — DataTables forums
Viewing all articles
Browse latest Browse all 35273

DataTables 1.10 - date range filter.

$
0
0

Hi All,

I know quite a few people have had issues with date range filters and it appears I'm no different.

I've got a table with multiple filters and trying to create one which returns table rows which ahve a date between this range.
This is what I've got so far:

the start date and end date are passed into the function as yyyymmdd without any seperator and the row date is formated the same.

$('#sMonth').change( function(e) {
// Date SEARCH functionality
var startD = $('#sDay').val();
var startM = $('#sMonth').val();
var startY = $('#sYear').val();

        var endD = $('#eDay').val();
         var endM = $('#eMonth').val();
         var endY = $('#eYear').val();

        e.preventDefault();
        var startDate =  startY + "-" + startM + "-" + startD;
            var endDate =  endY + "-" + endM + "-" + endD ;

            filterByDate(6, startDate, endDate);
            $('#csvOutput').DataTable().draw();

    });

This watches the input fields for change and then calls the below function (for now i have it only watching one input field)

function filterByDate(column, startDate, endDate) {
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var rowDate2 = aData[column].split("-");
rowDate2 = rowDate2[0].split("/");
rowDate2 = "20"+rowDate2[2] + "-" + rowDate2[1] + "-" + rowDate2[0];
var rowDate = normalizeDate(rowDate2),
start = normalizeDate(startDate),
end = normalizeDate(endDate);

      // If our date from the row is between the start and end
          if (start <= rowDate && rowDate <= end) {
            return true;
              } else if (rowDate >= start && end === '' && start !== ''){
                return true;
              } else if (rowDate <= end && start === '' && end !== ''){
                return true;
              } else {
                return false;
              }
            }

    );

}

It doesn't return any rows despite them being in the range and now no other filters work.
I've stepped into the function and can see that criteria are being met and return true is being triggered.

What am I doing wrong? PLEASE HELP! I'm pulling my hair out here and I've already got a receeding hairline! NOT GOOD!


Viewing all articles
Browse latest Browse all 35273

Trending Articles