Skip to content

Instantly share code, notes, and snippets.

@bj7
Created April 27, 2016 15:07
Show Gist options
  • Save bj7/9592f1fac488c7747e655ed95e3b7563 to your computer and use it in GitHub Desktop.
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 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