Created
April 27, 2016 15:07
-
-
Save bj7/9592f1fac488c7747e655ed95e3b7563 to your computer and use it in GitHub Desktop.
So apparently, Datatables applies custom filters globally, which will TOTALLY screw up your other tables. Recommended workaround is to test each table to ensure it’s the one to apply the filter to…What a joke. Easiest solution is to empty the array of custom filters and rebuild each time...
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
/** | |
* This function toggles the filter on campaigns with no clicks. | |
* @param {bool} toggle Boolean value of the toggled checkbox. | |
*/ | |
$scope.toggleShowCampsNoClicks = function(toggle) { | |
// filter the table to show the appropriate entries | |
localStorage.setItem('thrivetracker_showCampsNoClicks', toggle); | |
$scope.showCampsNoClicks = toggle; | |
// custom filter extension for hiding columns with 0 | |
jQuery.fn.dataTableExt.afnFiltering.push(function(oSettings, aData, iDataIndex) { | |
var t = $("#showNoClicks").prop("checked"); | |
// if we want to show all camps, then just return true, else only return true | |
// for when clicks are greater than 0; aData[3] == clicks | |
if (t === true) | |
return true; | |
else | |
return (aData[3] > 0); | |
}); | |
$scope.table.fnDraw(); | |
// EMPTY OUT THE CUSTOM FILTER BECAUSE DATATABLES IS RETARDED AND MAKES IT GLOBAL INSTEAD OF LOCAL ONLY... | |
jQuery.fn.dataTableExt.afnFiltering = []; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment