Hi All
Unfortunately, I can’t for some reason reply to the original post Show # of records on filters so have started a new post with a similar title.
Try as I could with AI all I could manage was to come tantalizingly close to a universal solution but unfortunately with inconsistent results written to the filter buttons. AI did however offer a workable solution so long as you’re not a very heavy user of the filter buttons.
The issue, as Norm mentioned, is to be able to read the record counts when the page is rendered rather than when the buttons are clicked. The solution provided is to create grid views, on the page, mimicking each of the filters. Quick and dirty will suffice as these will be hidden using the KTL keyword _hv. The important thing is the set the filters for the grids to be exactly the same as those for the filters.
//************** Inserts record counts into the filter buttons in view_2XX3 **************/
// Have to HIDE all of the grids created to obtain these record counts in view_2XX2, view_2XX4, view_2XX5, view_2XX6, & view_2XX7.
// Cache counts globally to avoid re-reading from hidden views
window.filterCountsCache_2XX3 = window.filterCountsCache_2XX3 || {};
function updateFilterCounts() {
var viewMap = {
“Today’s”: “view_2XX2”,
“All”: “view_2XX4”,
“Relieving”: “view_2XX5”,
“TIME OFF”: “view_2XX6”,
“UNAVAILABLE”: “view_2XX7”
};
var filterButtons = $(‘#view_2XX3 .js-filter-menu.tabs ul li a’);
if (filterButtons.length === 0) return;
// First, read and cache counts from hidden views if not already cached
var allCached = true;
for (var filterName in viewMap) {
if (!window.filterCountsCache_2XX3[filterName]) {
allCached = false;
var viewId = viewMap[filterName];
var count = $(‘#’ + viewId + ’ .kn-entries-summary’).text().match(/of (\d+)/);
if (count) {
window.filterCountsCache_2XX3[filterName] = count[1];
console.log('Cached ’ + filterName + ': ’ + count[1]);
}
}
}
// Apply counts from cache (instant, no DOM reading)
filterButtons.each(function() {
var $btn = $(this);
var btnText = $btn.find(‘span’).text().trim().replace(/\s*(\d+)/, ‘’);
if (window.filterCountsCache_2XX3[btnText]) {
$btn.find('span').text(btnText + ' (' + window.filterCountsCache_2XX3[btnText] + ')');
}
});
}
// Run immediately when view_2XX renders (no timeout for cached data)
$(document).on(‘knack-view-render.view_2XX3’, function(event, view, data) {
updateFilterCounts();
});
// Run when hidden views render to populate the cache
$(document).on(‘knack-view-render.view_2XX2 knack-view-render.view_2XX4 knack-view-render.view_2XX5 knack-view-render.view_2XX6 knack-view-render.view_2XX7’, function(event, view, data) {
setTimeout(updateFilterCounts, 50);
});
// Clear cache when navigating to a new page
$(document).on(‘knack-scene-render.any’, function(event, scene) {
window.filterCountsCache_2XX3 = {};
});



Dean