Created
January 4, 2019 11:53
-
-
Save stevepiercy/b1b3ab1098d2b1811f0987be7598c027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Source: | |
* https://github.com/DataTables/Plugins/blob/master/filtering/row-based/range_dates.js | |
* | |
* Filter a column on a specific date range. Note that you will likely need | |
* to change the id's on the inputs and the columns in which the start and | |
* end date exist. | |
* | |
* @name Date range filter | |
* @summary Filter the table based on two dates in different columns | |
* @author _guillimon_ | |
* | |
* @example | |
* $(document).ready(function() { | |
* var table = $('#example').DataTable(); | |
* | |
* // Add event listeners to the two range filtering inputs | |
* $('#min').keyup( function() { table.draw(); } ); | |
* $('#max').keyup( function() { table.draw(); } ); | |
* } ); | |
*/ | |
$.fn.dataTableExt.afnFiltering.push( | |
function( oSettings, aData, iDataIndex ) { | |
var iFini = document.getElementById('min').value; | |
var iFfin = document.getElementById('max').value; | |
var iStartDateCol = 2; | |
var iEndDateCol = 2; | |
iFini=iFini.substring(0,4) + iFini.substring(5,7)+ iFini.substring(8,10); | |
iFfin=iFfin.substring(0,4) + iFfin.substring(5,7)+ iFfin.substring(8,10); | |
var datofini=aData[iStartDateCol].substring(0,4) + aData[iStartDateCol].substring(5,7)+ aData[iStartDateCol].substring(8,10); | |
var datoffin=aData[iEndDateCol].substring(0,4) + aData[iEndDateCol].substring(5,7)+ aData[iEndDateCol].substring(8,10); | |
if ( iFini === "" && iFfin === "" ) | |
{ | |
return true; | |
} | |
else if ( iFini <= datofini && iFfin === "") | |
{ | |
return true; | |
} | |
else if ( iFfin >= datoffin && iFini === "") | |
{ | |
return true; | |
} | |
else if (iFini <= datofini && iFfin >= datoffin) | |
{ | |
return true; | |
} | |
return false; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment