FnFilter Conflict
FnFilter Conflict
bryceray1121
Posts: 65Questions: 0Answers: 0
I use a custom date sort filter for my tables. However, I've run into a problem that appears to be caused by a collision between my custom filter and the default filter.
Situation:
I initialize a table with this filter code:
[code]
var defaultMin = new Date(new Date().setMonth(new Date().getMonth() - 6)).getTime();
var filterDateTables = {};
filterDateTables["#labs-table"] = defaultMin;
filterDateTables["#labResults-table"] = defaultMin;
$jq.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var iMin = null;
var tableSrc = null;
for(key in filterDateTables){ //Check if the active table is in the the filterDateTables array
tableSrc = $jq(key)[0];
if(tableSrc == oSettings.nTable){
iMin = filterDateTables[key];
break;
}
}
if ( iMin == null )
{
return true;
}
var iMax = new Date().getTime();
var colIndex = $jq(".filterDate",tableSrc).parent().children().index($jq(".filterDate",tableSrc)); //Dynamically determine the index of the column which stores the date type
var iVersion = aData[colIndex] == "-" ? 0 : new Date(aData[colIndex]).getTime();
if ( iMin == "" && iMax == "" ) {
return true;
}
else if ( iMin == "" && iVersion < iMax ) {
return true;
}
else if ( iMin < iVersion && "" == iMax ) {
return true;
}
else if ( iMin < iVersion && iVersion < iMax ) {
return true;
}
return false;
}
);
filterByDate = function(id,months){ //onclick function
var min = "";
if($jq(id).is(':visible')){
if(months !== undefined){ //If no month is defined display all results
min = new Date(new Date().setMonth(new Date().getMonth() - months)).getTime(); //Subtract user defined months from current date to determine minimum date.
}
filterDateTables[id] = min; //Set min
$jq(id).dataTable().fnDraw(); //Apply filter
}
}
[/code]
I then want to go to that table and do a regular text search using the default fnfilter. However, when I do this the table automatically returns no results. Even though there are results to be returned. If I then temporarily disable the above code and do the same thing it returns results.
Any ideas on why the above code is breaking the default fnfilter?
Let me know if you need more information.
THanks.
Situation:
I initialize a table with this filter code:
[code]
var defaultMin = new Date(new Date().setMonth(new Date().getMonth() - 6)).getTime();
var filterDateTables = {};
filterDateTables["#labs-table"] = defaultMin;
filterDateTables["#labResults-table"] = defaultMin;
$jq.fn.dataTableExt.afnFiltering.push(
function( oSettings, aData, iDataIndex ) {
var iMin = null;
var tableSrc = null;
for(key in filterDateTables){ //Check if the active table is in the the filterDateTables array
tableSrc = $jq(key)[0];
if(tableSrc == oSettings.nTable){
iMin = filterDateTables[key];
break;
}
}
if ( iMin == null )
{
return true;
}
var iMax = new Date().getTime();
var colIndex = $jq(".filterDate",tableSrc).parent().children().index($jq(".filterDate",tableSrc)); //Dynamically determine the index of the column which stores the date type
var iVersion = aData[colIndex] == "-" ? 0 : new Date(aData[colIndex]).getTime();
if ( iMin == "" && iMax == "" ) {
return true;
}
else if ( iMin == "" && iVersion < iMax ) {
return true;
}
else if ( iMin < iVersion && "" == iMax ) {
return true;
}
else if ( iMin < iVersion && iVersion < iMax ) {
return true;
}
return false;
}
);
filterByDate = function(id,months){ //onclick function
var min = "";
if($jq(id).is(':visible')){
if(months !== undefined){ //If no month is defined display all results
min = new Date(new Date().setMonth(new Date().getMonth() - months)).getTime(); //Subtract user defined months from current date to determine minimum date.
}
filterDateTables[id] = min; //Set min
$jq(id).dataTable().fnDraw(); //Apply filter
}
}
[/code]
I then want to go to that table and do a regular text search using the default fnfilter. However, when I do this the table automatically returns no results. Even though there are results to be returned. If I then temporarily disable the above code and do the same thing it returns results.
Any ideas on why the above code is breaking the default fnfilter?
Let me know if you need more information.
THanks.
This discussion has been closed.
Replies
Allan