custom date range filter on click of a button
custom date range filter on click of a button
sreenu539
Posts: 10Questions: 2Answers: 0
I am using the following example as the base for the date range filtering, however I do want the filtering to happen exclusively when a button is clicked rather than on typing a date in date range input fields. I need to do some validations and show messages to the user based on the dates they enter, so needed this. If validations pass through then only the filtering should get executed.
I am testing this in IE8.
For now, i am just providing some pseudo code.
[code]
var btnClick = false; //global var
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
/
if(btnClick){
var dateRange = $('#date-range').attr("value");
// parse the range from a single field into min and max, remove " - "
dateMin = dateRange.substring(0,4) + dateRange.substring(5,7) + dateRange.substring(8,10);
dateMax = dateRange.substring(13,17) + dateRange.substring(18,20) + dateRange.substring(21,23);
// 4 here is the column where my dates are.
var date = aData[4];
// remove the time stamp out of my date
// 2010-04-11 20:48:22 -> 2010-04-11
date = date.substring(0,10);
// remove the "-" characters
// 2010-04-11 -> 20100411
date = date.substring(0,4) + date.substring(5,7) + date.substring( 8,10 )
// run through cases
if ( dateMin == "" && date <= dateMax){
return true;
}
else if ( dateMin =="" && date <= dateMax ){
return true;
}
else if ( dateMin <= date && "" == dateMax ){
return true;
}
else if ( dateMin <= date && date <= dateMax ){
return true;
}
// all failed
return false;
}
else{
//return all all records when there is no filtering or else case of btnClick
return true;
}
);
function dateRangeValidation(){
//validations pass thru
btnClick = true;
oTable.fnDraw();
}
[/code]
1) I am not sure why the push method always get called, as soon as the date entered in the date range input boxes NOTE:- I removed all keyup, change events on date range input elements, still the push method gets called on every input in the date range input boxes.
2) to stop this auto calling I am using [quote] btnClick[/quote] variable as flag to execute the push method code.
3) once the "button" clicked , it is executing validations, set the btnClick flage and then filter.
4) Now the issue : on removing dates in date range input boxes, the filtering is happening again .
[quote]I just want the filtering to happen only on click of the button[/quote] not on input of date in date range input boxes.
I could provide more actual code, if needed , basically the above is the essence of what I am trying to do.
I really appreciate if people here could help me!
I am thinking about fnDrawCallBack method, but need to try this.
Thank you,
Sree
I am testing this in IE8.
For now, i am just providing some pseudo code.
[code]
var btnClick = false; //global var
$.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
/
if(btnClick){
var dateRange = $('#date-range').attr("value");
// parse the range from a single field into min and max, remove " - "
dateMin = dateRange.substring(0,4) + dateRange.substring(5,7) + dateRange.substring(8,10);
dateMax = dateRange.substring(13,17) + dateRange.substring(18,20) + dateRange.substring(21,23);
// 4 here is the column where my dates are.
var date = aData[4];
// remove the time stamp out of my date
// 2010-04-11 20:48:22 -> 2010-04-11
date = date.substring(0,10);
// remove the "-" characters
// 2010-04-11 -> 20100411
date = date.substring(0,4) + date.substring(5,7) + date.substring( 8,10 )
// run through cases
if ( dateMin == "" && date <= dateMax){
return true;
}
else if ( dateMin =="" && date <= dateMax ){
return true;
}
else if ( dateMin <= date && "" == dateMax ){
return true;
}
else if ( dateMin <= date && date <= dateMax ){
return true;
}
// all failed
return false;
}
else{
//return all all records when there is no filtering or else case of btnClick
return true;
}
);
function dateRangeValidation(){
//validations pass thru
btnClick = true;
oTable.fnDraw();
}
[/code]
1) I am not sure why the push method always get called, as soon as the date entered in the date range input boxes NOTE:- I removed all keyup, change events on date range input elements, still the push method gets called on every input in the date range input boxes.
2) to stop this auto calling I am using [quote] btnClick[/quote] variable as flag to execute the push method code.
3) once the "button" clicked , it is executing validations, set the btnClick flage and then filter.
4) Now the issue : on removing dates in date range input boxes, the filtering is happening again .
[quote]I just want the filtering to happen only on click of the button[/quote] not on input of date in date range input boxes.
I could provide more actual code, if needed , basically the above is the essence of what I am trying to do.
I really appreciate if people here could help me!
I am thinking about fnDrawCallBack method, but need to try this.
Thank you,
Sree
This discussion has been closed.