I keep a little webpage that generates tables of data about migration at the U.S.-Mexico border, using CBP’s regularly updated dataset.

For weeks, I’ve wanted to have the ability to sort the tables by clicking on their column headers. It seemed like a big job, though, especially figuring out how to keep the columns’ totals at the bottom, not included in the sort.

This evening, though, I thought to ask ChatGPT—and it gave me exactly what I wanted, with only a couple of dozen lines of code. Here’s what the tables can do now:

Animated GIF of the table being resorted, in descending and ascending order, when column headers are clicked.

The whole process took less than 20 minutes: two queries and me copy-pasting the code into the page. It works flawlessly, which is very cool, and perhaps a bit creepy.

Try it out here.