upvote
This is… not obvious. It's only easy if you want the simplistic approach of sorting lexicographically or numerically. But in more complex tables, you will often encounter cases where the data representation for sorting is different from data representation for display.

Of course most JavaScript-based tables get this wrong, too.

reply
You could have a `sortkey` attribute, a bit like <option> that has a `value` attribute in case the value you want is different from the value you display.
reply
I feel like there's so few times it would actually work how I want it that it seems like there's little point.
reply
You want client side table sorting?

It's really easy to do this with server rendered HTML. Put a link with the sort param in the column headers and be done.

reply
I used to do this in the early 2000s! Some folks back then would ask whether i was afraid that clicking a link (which loads a "new" web page) would slow things down and create an awful experience for users...but, my team and I would really focus on keeping web pages slim/lightweight to begin with...so it rarely was a problem. I don't think we were geniuses or anything like that, but keeping things light (always and from the beginning) enabled us to "cheat" (like this "hack" of the links in the column headers) in ways that were beneficial but with very low risk. Sometimes it took an extra moment or two at the beginning of an effort...but it ALWAYS paid off down the road, and in many different ways.
reply
It still works exceptionally well in 2026 and generally creates better and faster experiences than an SPA with far, far less code.
reply
You don’t need an SPA for that; Wikipedia has client-side sorted tables for example.
reply
I hate what it does to my back button
reply
HTMX is the solution
reply
So instead of using JS to sort the table directly, now you make a JS fetch() request to sort the table?!

It does make sense in one situation, if the table is a large server-side paginated one and the sorting is really an ORDER BY clause. But for a basic table that fits entirely on the client, it doesn't make sense at all. There are tiny JS libraries that will make <table>s sortable when you add a particular class name.

reply
Trading one javascript for another?
reply
I want tables that can be sorted on multiple columns without triggering a page refresh on every click.
reply
View Transitions are your friend
reply
deleted
reply
That's what javascript is supposed to be for. All of this is what javascript is supposed to be for.

HTML describes layout, CSS describes style, JS adds interactivity.

Want sortable tables? Get a jquery plugin and spend five minutes, done.

This was all solved a decade or more ago.

reply
> Want sortable tables? Get a jquery plugin and spend five minutes, done.

I want sortable tables without having to rely on a third-party plugin to a third-party library. HTML describes content, not just layout. It would be a `sortable` attribute on the table, just like you already have attributes that have nothing to do with layout such as `autocomplete` or `aria-*`.

reply
Everyone already complains that browsers are too bloated and now you want to have every browser support sortable tables when a single, simple JS file would work?
reply
> HTML describes layout

News to me.

reply
That's understandable, because almost no one actually works with HTML directly anymore, but it's true. HTML contains tags like <H> for headers, <p> for paragraphs, <br> for line breaks <pre> for prerendered text, <ol> and <ul> for ordered and unordered lists, <table> for tables as well as <main>,<div>,<header>,<section>,<nav>,<article>,<aside>,<summary> and <footer> to both explicitly and implicitly describe the layout of an HTML document. In fact, "HTML" itself is an acronym (HyperText Markup Language) in which the "Markup" describes the function of HTML to "mark up" text in a similar way that editors once did in the print industry, describing which parts of the text should be bold, italicized, etc. or divided up and in what way.
reply
HTML describes the structure of a document, not really the layout.

If HTML had <inline> <block> <column> <row> or <grid> tags, sure. But CSS determines the layout via display/position properties.

reply
<span> is inline

<div> is block

<table>,<tr> and <td> are your grid, row and column.

CSS improves on describing layout with positioning but HTML was still doing that before CSS even came along.

reply