I’ve been putting together a proper filter bar for the blog list: language, date range, sort, and pagination that stays snappy with HTMX. It’s close now—but as always, the last 20% is the spicy bit: dates, caches, and “why does that work locally but not after a swap?”
If you want the deep dive with lots of code and diagrams, see: /blog/filterbarprogressandissues
remember this site is a work in progress, this sort of stuff WILL happen when you eat-your-own-dogfood!
/blog/calendar-days endpointLinkUrl is set on the server)// Server: cache and vary for index
[ResponseCache(Duration = 300, VaryByHeader = "hx-request",
VaryByQueryKeys = new[] { "page", "pageSize", nameof(startDate), nameof(endDate), nameof(language), nameof(orderBy), nameof(orderDir) },
Location = ResponseCacheLocation.Any)]
[OutputCache(Duration = 3600, VaryByHeaderNames = new[] { "hx-request" },
VaryByQueryKeys = new[] { nameof(page), nameof(pageSize), nameof(startDate), nameof(endDate), nameof(language), nameof(orderBy), nameof(orderDir) })]
public async Task<IActionResult> Index(int page = 1, int pageSize = 20, DateTime? startDate = null, DateTime? endDate = null,
string language = MarkdownBaseService.EnglishLanguage, string orderBy = "date", string orderDir = "desc")
{
var posts = await blogViewService.GetPagedPosts(page, pageSize, language: language, startDate: startDate, endDate: endDate);
posts.LinkUrl = Url.Action("Index", "Blog", new { startDate, endDate, language, orderBy, orderDir });
if (Request.IsHtmx()) return PartialView("_BlogSummaryList", posts);
return View("Index", posts);
}
The biggest addition: proper post visibility management:
IsHidden flag) and won't appear in listingsScheduledPublishDate and only appear after that timeIsPinned always appear first on page 1 (great for announcements)// BlogService now filters appropriately
var now = DateTimeOffset.UtcNow;
postQuery = postQuery.Where(x =>
!x.IsHidden &&
(x.ScheduledPublishDate == null || x.ScheduledPublishDate <= now));
// Pinned posts sorted first on page 1
if (isFirstPage)
{
postQuery = postQuery.OrderByDescending(x => x.IsPinned)
.ThenByDescending(x => x.PublishedDate.DateTime);
}
/blog/date-range endpoint: Returns the min/max dates across all posts (language-aware) so the date picker can set sensible bounds<clear-param> tag helper to easily clear query parameters<clear-param name="startDate">Clear Date</clear-param>
<clear-param all="true" exclude="language">Clear All Filters</clear-param>
new URL(window.location.href) and only override the changing params; if Flatpickr has a selection, re-apply it.langSelect.addEventListener('change', async function(){
const u = new URL(window.location.href);
u.searchParams.set('language', langSelect.value);
u.searchParams.set('page','1');
const [ob,od] = (orderSelect.value||'date_desc').split('_');
u.searchParams.set('orderBy', ob);
u.searchParams.set('orderDir', od);
if(input._flatpickr && input._flatpickr.selectedDates.length===2){
const [s,e] = input._flatpickr.selectedDates;
u.searchParams.set('startDate', s.toISOString().substring(0,10));
u.searchParams.set('endDate', e.toISOString().substring(0,10));
}
applyNavigation(u);
});
Calendar highlights not refreshing after HTMX swaps
fp.redraw(); also re-run init on htmx:afterSwap.Dark mode styles not applying to the calendar
<html class> and call fp.redraw() when it changes.sequenceDiagram
participant User
participant JS as blog-index.js
participant HT as HTMX
participant S as Server
User->>JS: Change language/order or pick a date range
JS->>JS: Update URLSearchParams, pushState
JS->>HT: htmx.ajax('GET', /blog?...)
HT->>S: GET /blog
S-->>HT: HTML partial (_BlogSummaryList)
HT-->>User: Swap #content
The filter bar uses a custom pagerequest header to help the server distinguish between full page loads and partial HTMX swaps:
public static bool IsPageRequest(this HttpRequest request)
{
return request.Headers.ContainsKey("pagerequest") &&
request.Headers["pagerequest"] == "true";
}
This allows the controller to return just the partial view for HTMX requests and full page views for direct navigation.
Note: The paging tag helper extension and query parameter clearer Alpine.js component deserve their own deep dive—I'll cover these in detail in a future post about building reusable HTMX/Alpine components.
Spotted an issue? Please drop a comment with your browser + steps.
© 2025 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.