Custom Filter and Datepicker not working together
Custom Filter and Datepicker not working together
ksailorgirl1
Posts: 2Questions: 0Answers: 0
I am trying to write a custom Filter and I cannot get the Datepicker to work at the same time. I did the datatables debugger and it gave me the code: owuniy. I am definitely not a programmer so I am really struggling. I want to filter a Start Date column and an End Date column. I know this is something other people have requested before but I cannot find anywhere that it has actually been done with the datepicker. ANY help would be greatly appreciated. Please let me know if you see any obvious mistakes.
[code]
Page Title Goes Here
var minDateFilter;
var maxDateFilter;
var minData;
var maxData;
$.fn.dataTableExt.afnFiltering.push(
function ( oSettings, aData, iDataIndex ) {
minData = new Date(aData[1]).getTime();
maxData = new Date(aData[2]).getTime();
if ( minDateFilter == "" && maxDateFilter == "" )
{
return true;
}
elseif (minDateFilter <= minData && maxDateFilter == "" )
{
return true;
}
elseif (maxDateFilter >= maxData && minDateFilter == "" )
{
return true;
}
elseif (minDateFilter <= minData && maxDateFilter >= maxData)
{
return true;
}
return false;
}
);
$(document).ready( function() {
var oTable = $('#example').dataTable( {
"bJQueryUI": true
} );
$( "#datepicker_min" ).datepicker( {
"onSelect": function(date) {
minDateFilter = new Date(date).getTime();
oTable.fnDraw();
}
} ).keyup( function () {
minDateFilter = new Date(this.value).getTime();
oTable.fnDraw();
} );
$( "#datepicker_max" ).datepicker( {
"onSelect": function(date) {
maxDateFilter = new Date(date).getTime();
oTable.fnDraw();
}
} ).keyup( function () {
maxDateFilter = new Date(this.value).getTime();
oTable.fnDraw();
} );
} );
Live example
Min date: Max date:
Event
Start Date
End Date
Best Parade Evar
01/09/2013
01/12/2013
Rastling Showdown
03/04/2014
03/21/2014
Rough Rodeo
02/01/2013
02/01/2013
[/code]
[code]
Page Title Goes Here
var minDateFilter;
var maxDateFilter;
var minData;
var maxData;
$.fn.dataTableExt.afnFiltering.push(
function ( oSettings, aData, iDataIndex ) {
minData = new Date(aData[1]).getTime();
maxData = new Date(aData[2]).getTime();
if ( minDateFilter == "" && maxDateFilter == "" )
{
return true;
}
elseif (minDateFilter <= minData && maxDateFilter == "" )
{
return true;
}
elseif (maxDateFilter >= maxData && minDateFilter == "" )
{
return true;
}
elseif (minDateFilter <= minData && maxDateFilter >= maxData)
{
return true;
}
return false;
}
);
$(document).ready( function() {
var oTable = $('#example').dataTable( {
"bJQueryUI": true
} );
$( "#datepicker_min" ).datepicker( {
"onSelect": function(date) {
minDateFilter = new Date(date).getTime();
oTable.fnDraw();
}
} ).keyup( function () {
minDateFilter = new Date(this.value).getTime();
oTable.fnDraw();
} );
$( "#datepicker_max" ).datepicker( {
"onSelect": function(date) {
maxDateFilter = new Date(date).getTime();
oTable.fnDraw();
}
} ).keyup( function () {
maxDateFilter = new Date(this.value).getTime();
oTable.fnDraw();
} );
} );
Live example
Min date: Max date:
Event
Start Date
End Date
Best Parade Evar
01/09/2013
01/12/2013
Rastling Showdown
03/04/2014
03/21/2014
Rough Rodeo
02/01/2013
02/01/2013
[/code]
This discussion has been closed.