Marc, I'm also having problems to make the filter button appear with the new knack standard theme. Anyone figured out how to solve it?
Here is my code that was working with old theme:
// Filtro de Colunas
$(document).on('kn-table-wrapper.view_289.view_1111.view_1118.view_1119.view_1488.view_940.view_1105.view_1073.view_1411.view_1410.view_1375.view_1469.view_1761', function(event, view, data) {
addTableColumnChoose(view);
});
var addTableColumnChoose = function(view) {
//See http://helpdesk.knackhq.com/support/discussions/topics/5000074312 and https://jsfiddle.net/HvA4s/
// added support for cookies to keep selected columns between renders and sessions
var clearFix = $('#' + view.key + ' div.kn-records-nav.clearfix');
clearFix.append("<div class='clear'><a href='#' class='choose-columns'>▼ Ocultar Coluna(s)</a></div>");
var hstring = getCookie("hstring_"+view.key);
if (hstring != ''){
var headers = JSON.parse(hstring);
$.each(headers, function(i, show) {
var cssIndex = i + 1;
var tags = $('#' + view.key + ' table th:nth-child(' + cssIndex + '), #' + view.key + ' table td:nth-child(' + cssIndex + ')');
if (show)
tags.show();
else
tags.hide();
});
}
$('#' + view.key + ' .choose-columns').click(function() {
// remove other open columns set dialog on the same page
if( $('#tableChooseColumns')!=null) {$('#tableChooseColumns').remove();}
var headers = $('#' + view.key + ' table th').map(function() {
var th = $(this);
return {text: th.text(), shown: th.css('display') != 'none'};
});
var hs;
h = ['<div id=tableChooseColumns><table><thead><tr><td style="height: 0px; border-bottom: 2px solid; padding: 7px 0px 7px 0px;">FILTRAR</td></tr></thead><tbody><tr>'];
$.each(headers, function() {
h.push('<tr><td style="padding:5px 0px 3px 0px;"><input type=checkbox',
(this.shown ? ' checked ' : ' '),
'/> ',
this.text,
'</td></tr>');
});
h.push('</tr></tbody></table><button id=done>Aplicar</button></div>');
hs = h.join('');
$('body').append(hs);
var pos = $('#' + view.key + ' .choose-columns').position();
$('#tableChooseColumns').css({'position': 'absolute','right': '24px', 'margin-top': '-50px', 'z-index': '9999', 'top': pos.top,'padding': '5px', 'background': 'rgb(118, 138, 158)', 'box-shadow': '0 0px 0px 0 rgba(0, 0, 0, 0.2), 0px 4px 10px 0 rgba(0, 0, 0, 0.19)', 'font-size': '14px', 'color': '#fff', 'border': '2px solid #fff', 'border-radius': '12px'});
$('#done').click(function() {
var showHeaders = $('#tableChooseColumns input').map(function() { return this.checked; });
var columns =[];
$.each(showHeaders, function(i, show) {
var cssIndex = i + 1;
var tags = $('#' + view.key + ' table th:nth-child(' + cssIndex + '), #' + view.key + ' table td:nth-child(' + cssIndex + ')');
if (show)
tags.show(300,"swing");
else
tags.hide(300,"swing");
columns.push(show);
});
$('#tableChooseColumns').remove();
setCookie("hstring_"+view.key,JSON.stringify(columns),100);
mixpanel.track("Preferences changes",{"Page":("Knack: "+view.scene.name), "View":view.title});
return false;
});
return false;
});
}
/* Cookie support -----------------------------------------------*/
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length,c.length);
}
}
return "";
}
// handler to dismiss dialog just with outside click
$(document).click(function(event) {
if(!$(event.target).closest('#tableChooseColumns').length) {
if($('#tableChooseColumns').is(":visible")) {
$('#tableChooseColumns').remove();
}
}
})