Super-easy filterable lists/tables with jQuery

I’m working on a page that will potentially have a very long table of information, and I wanted a way to filter the table to only show rows that contain a specific text string.

Fortunately, with jQuery that’s super easy. It took me about 3 minutes to build and test. Let’s take a look!

First, you want to create your table. Give it a class you’ll be able to use to tell jQuery this is what you’re filtering. Something like this:

<table class="filterable">
  <tbody>
    <tr>…</tr>
  </tbody>
</table>

Now let’s put in a little form field for entering the filter string. This is old news now, but HTML5 lets us use one-off form inputs for on-page actions without having to wrap them in a <form> tag, so let’s just stick this into our HTML above the table:

<div>
  Filter: <input type="text" id="list_filter" />
</div>

Now here’s where it gets fun. In jQuery, we’re going to watch for the keyup event on the input. If the input has a value (i.e. is not empty), we’ll do our filtering. If it is empty, we’ll just reveal all of the rows in the table again.

We probably want the filter to be case-insensitive, so we’ll make both the input string and our check of each row’s text all-lowercase with .toLowerCase().

Next we’ll step through each row of the table, check if our filter string is not present (.indexOf() == -1) in the .text() inside that row. If it’s not there, we’ll hide the row. Otherwise, we’ll show it. (This last bit is important because we want to start revealing previously hidden rows if the user deletes characters from the filter input.)

Yeah… that’s pretty much it. And since it’s all jQuery interacting with elements already present on the page, it’s lightning-fast.

<script>
  jQuery(function() {
    jQuery('input#list_filter').on('keyup', function() {
      if (jQuery(this).val() != '') {
        var filter_val = jQuery(this).val().toLowerCase();
        jQuery('table.filterable tbody tr').each(function() {
          if (jQuery(this).text().toLowerCase().indexOf(filter_val) == -1) {
            jQuery(this).hide();
          }
          else {
            jQuery(this).show();
          }
        });
      }
      else {
        jQuery('table.filterable tbody tr').show();
      }
    });
  });
</script>

A few other notes:

  1. The way this is built, you could conceivably have multiple filterable tables on one page, but only one filter input. The filter would automatically get applied to all filterable tables on the same page. There are various ways of changing this by modifying your selector.
  2. I am deliberately only checking for <tr> tags inside the <tbody> tag to allow for a header row inside a <thead> tag that would not be subject to the filter. If you have a header row inside your <tbody> tag, it’s going to get filtered too! Probably not desirable.
  3. You could play around with making the whole thing smoother with .slideUp() and .slideDown() instead of .hide() and .show() but that UX can get messy in a hurry.

Responsive horizontal scrolling tables for phones in CSS with no additional HTML

For some reason I always forget how to do this, and most tutorials out there suggest wrapping your table in a container <div> tag but as long as you’re using <tbody> (and, ideally, not using <thead> or <tfoot>) then it’s easy with a small bit of CSS and no HTML changes at all.

The trick is to display your <table> as a block, and your <tbody> as a table!

Here’s the code. Fit it into whichever breakpoint makes sense for your site. Mine shown here is the standard phone width breakpoint for WordPress (782 pixels):

@media screen and (max-width: 782px) {

  table {
    display: block;
    overflow-x: auto;
    width: 100%;
  }

  table tbody {
    display: table;
    width: auto;
  }

}

Of course, right after I posted this I found that I had already written about it two years ago with a slightly different solution. Never hurts to have a slightly different perspective.

All the Albums of 2019

It’s been an annual tradition here on Underdog of Perfection: Around the end of November, I post a list of all of the albums I’ve purchased that year, and then a couple weeks later, I rank my top 5.

Well… I skipped it altogether last year, because I hadn’t been paying much attention to new music. The trend has only accelerated this year. It’s partly because I’ve been delving deeply into jazz from the ’60s and ’70s, but it’s more because… man, pop music really sucks these days, and I just haven’t been too interested in the more obscure new stuff either.

And of course, who “buys albums” anymore?

So, here then is my complete list of all the new albums I purchased in 2019. Ones I think are especially good are in bold.

Christopher Willits — Sunset
The Claypool Lennon Delirium — South of Reality
Com Truise — Persuasion System
John Coltrane — Blue World*
JV’s Boogaloo Squad — Going to Market
Lizzo — Cuz I Love You
Mario Alberto Silva — Pan-American Sonata
Steve Hauschildt — Nonlin
The Bad Plus – Activate Infinity
The Bird and the Bee — Interpreting the Masters, Volume 2: A Tribute to Van Halen
TOOL — Fear Inoculum
32nd Street Jazz — self-title**

* Technically a new release!

** OK, I didn’t buy this… I made it, along with my bandmates. But hey, it’s a real release… we even got a ton of airplay on Jazz 88 in August and September! (And yes, it is one of my favorite albums of the year.)

And while I’m at it, here’s my complete (and considerably longer, but still short) list of all the new albums I purchased in 2018, favorites in bold.

Aphex Twin — Collapse EP
The Bad Plus — Never Stop II
Brad Mehldau Trip — Seymour Reads the Constitution!
Christian McBride — Christian McBride’s New Jawn
Courtney Barnett — Tell Me How You Really Feel
The Decemberists — I’ll Be Your Girl
Delvon Lamarr Organ Trio — Live at KEXP!
Elvis Costello & The Impostors — Look Now
Geotic — Traversa
Halloween, Alaska — Le Centre
Helios — Veriditas
Joshua Redman, Ron Miles, Scott Colley & Brian Blade — Still Dreaming
Justin Timberlake — Man of the Woods
Kamasi Washington — Heaven and Earth
King Crimson — Meltdown (Live in Mexico 2017)
Myriad3 — Vera
OMEGA Danzer — FUTURA the Album
Optiganally Yours — O.Y. in Hi-Fi
Steve Hauschildt — Dissolvi
X-Altera — self-title
Yellowjackets — Raising Our Voice
Yes — Fly From Here (Return Trip)

Using The SEO Framework with Advanced Custom Fields

I’m going to go out on a limb and guess that I am not the only WordPress developer who in recent days (in the wake of their obnoxious Black Friday dashboard ad) has switched allegiance from Yoast to another SEO plugin, and that many of those who find themselves in a similar boat (to mix metaphors) have switched to The SEO Framework.

I’ve only been using it for a couple of days, but I already love it. It does all of the things I actually used Yoast for, without any of the other stuff I did not use it for. I mean honestly, maybe readability scores and “cornerstone content” do provide an SEO boost, but I barely understand how to use these tools, so good luck explaining them to my clients in a meaningful way. I suppose they’re more of a tool for full-time SEO consultants who need to pad out their billable hours. (Sorry not sorry. My opinion on the business of SEO hasn’t changed all that much since 2011.)

It wasn’t until the Black Friday ad that I really admitted to myself how much I don’t like Yoast. It does a lot of important things, and does them very well. But it’s obnoxious as hell about it. Pushing features you don’t really want or need into every page of the WordPress admin, and plastering its own over-designed admin screens with tons of garish ads promoting its “premium” features.

Yuck.

The SEO Framework encapsulates all of the key features I liked about Yoast into a single configuration screen, which kindly adheres to the standard WordPress admin UI design language instead of infusing its own brand style into every button and metabox border. It’s refreshingly boring to look at. And it just has the stuff I actually use, like title and description, OpenGraph tags, sitemap XML, the basic elements of SEO that unequivocally matter and can be a pain to build and maintain on your own.

But enough about all of its great features. There’s one key thing it lacks: support for Advanced Custom Fields. My standard “modular design” theme relies almost entirely on ACF’s Flexible Content fields to work its page layout magic, and with all of the page content stored in custom fields instead of post_content, there’s nothing for The SEO Framework to latch onto to auto-generate meta descriptions.

Fortunately, the developer has built in some hooks to allow you to customize the meta description output.

Here’s a barebones starting point:

function my_seo_framework_description($description, $args) {
  if (empty($description)) {
    $description = ''; // Add your own logic here!
  }
  return $description;
}
add_filter('the_seo_framework_custom_field_description', 'my_seo_framework_description', 10, 2);
add_filter('the_seo_framework_generated_description', 'my_seo_framework_description', 10, 2);
add_filter('the_seo_framework_fetched_description_excerpt', 'my_seo_framework_description', 10, 2);

As the developer notes, it’s very important for SEO not to just output the same static description text on every page. You need to have a function of your own that will read your ACF field content and generate something meaningful here.

Fortunately in my case, I had already done that, for generating custom excerpts from ACF content, so I was able to just stick a call to that function into the // Add your own logic here! line. You’ll need to customize your function to suit your specific content structure, but here’s the post that I used as a starting point for my function.

Have fun!

A detailed look at my “Frankenstein” fretless Fender Jazz Bass

I got my first bass — a black Fender Standard (MIM) Jazz Bass — when I was in high school. It wasn’t perfect, but it was a great starter bass. And even though I didn’t really like the black body — I’ve always found black and sunburst to be the most boring and overused guitar finishes — I loved that bass until I could afford to buy a better one, ten years later.

But I always felt like that bass was flawed because of something that was my own fault. I was a curious kid, and one night I decided to take the bass apart. I mean, absolutely as far apart as I could. I removed the strings, the neck, the pickguard, the control plate, the pickups, the bridge… I think I even removed the tuning machines and bridge saddles. And then I put it all back together again.

But I didn’t know what I was doing. I didn’t know that the pickup height should be adjusted for optimal volume balance, so I just cranked them all the way down. I didn’t know that the bridge saddles needed to be adjusted in two dimensions for optimal tuning and playability, so it was out of tune and had terrible action. I didn’t know that the neck tension rod should be adjusted so there was just the slightest concave curve to the neck, so I had fret buzz.

Basically, I just thought it was a mediocre instrument, when in fact I had made it that way.

The lesson I learned was that I should not make any adjustments to my instruments, and it took me decades to get over that.


Fast forward to 2019. I’ve been playing bass in a jazz quartet for a couple of years now, and I’ve been buying new basses! For the past decade I’d owned a really nice Fender Jaguar Bass (MIJ) — red with matching headstock and block inlays — and a kind-of-crappy 5-string MIM Jazz Bass. I decided since I was playing jazz, I needed a fretless, so I went for a minimal expenditure and bought a Squier Vintage Modified Jazz Bass.

I couldn’t believe how good the Squier was for the price! Better than my MIM Fender! So I decided to sell the 5-string. I was hardly playing it anyway. I was curious about short-scale basses, so I bought a MIM Fender Mustang. But I hated it. The quality was crap. I don’t know what’s going on in Fender’s Ensenada factory these days, but I’m not impressed.

For those who don’t know, Squier is Fender’s entry-level sub-brand. Originally a mid-level line made in Japan, then for many years they were very poorly made in China. These days, I’ve since learned, they’re mostly made in Indonesia, using mostly CNC robots (rather than overworked and mistreated human laborers) to keep costs low but consistency and quality much higher than their reputation would lead one to believe.

I also realized short scale was a bad choice if I was simultaneously trying to regain my feel for fretless, so I returned the Mustang and bought… a Squier Vintage Modified 5-string Jazz Bass. It’s also surprisingly great!

Then earlier this year I sold the Jaguar and upgraded to my first ever Precision Bass, an American Professional. It looks just like the bass I learned on that I borrowed from my high school, before I got that first black Jazz Bass. I love it!

But that got me thinking… now that I have a nice solid American Professional instrument, I wanted to tinker a bit with another bass.

As good as the Squier fretless was, I hated two things about it: the synthetic fingerboard material (it just didn’t give enough of a “woody” sound), and the boring sunburst finish. (See above.) By now I’m comfortable adjusting the neck tension, action, tuning, and pickup height, so the idea of doing some customizations (just not to my expensive American Professional!) is not intimidating anymore.

For 2019 Fender introduced a new “Classic Vibe” Squier series, and there I saw the bass of my dreams… a “Daphne blue” Jazz Bass. But it only came in fretted. So I decided this would become the basis for my Frankenstein monster!


Fast forward a few more months, and now the monster is complete. Pretty much the only parts of it that are still the original Squier are the blue body, the tortoise shell pickguard, and the control plate. Everything else is new, with the exception of the tuning machines, which I stole off the Squier fretless (I’ll get to that).

I just love that look of the Daphne blue body paint with the tortoise shell pickguard. That was the inspiration to make all of this happen!

Yes, there’s a bit of headstock vanity, as much as I’m ashamed to admit it… gotta have that Fender logo! But the main reason I wanted this Fender neck, instead of just sticking the Squier fretless neck I already had onto this (which I did, initially), was to get that nice rosewood fingerboard.

Funny thing… when you buy a stock neck from Fender, they really just send you the neck. It just has 4 holes in it for the tuning machines, but you have to supply those yourself. I could have bought a set, but I figured I’d just use the ones from the old Squier fretless neck that I didn’t need anymore. Of course, the screw holes didn’t line up quite right, so I had to drill new ones.

Nuts. The other thing about the stock neck is that the string grooves in the nut aren’t really there… just little pilot notches. You’re supposed to file it down yourself. But a set of nut files is like $80! I considered buying some, but then I learned that this synthetic nut material is soft enough that you can actually “file” it with a set of roundwound strings… so that’s what I did! (I play the fretless with flatwounds.) It’s not totally perfect, but it worked surprisingly well and didn’t cost a thing!

Seriously? Did I really need to swap out the neck mounting plate? Well, yes and no. No, of course I didn’t. But I kind of wanted to, to get rid of any traces of “Squier.” But there was actually a good, practical reason for this. I wasn’t 100% sure the screw holes for mounting the neck would line up properly between a Squier body and a Fender neck. I was pretty sure they would. But not positive. This was an inexpensive (about $15) way to confirm that it would work, before spending a couple hundred bucks on a neck. It worked!

A Fender hi-mass bridge. The stock Squier bridge was perfectly fine, but I didn’t care much for the changes they made to the bridge saddles with the Classic Vibe series. Initially I swapped in the saddles from the Vintage Modified fretless, but a hi-mass bridge is not a huge investment and it does improve sustain… plus it just looks better.

DiMarzio noiseless pickups. Without a doubt this was the best upgrade across the board. The stock pickups just had kind of a weak and undefined sound… it was impossible to get that classic Jazz Bass “twang” from the bridge pickup. Plus you could never really solo one pickup because the 60 Hz hum was awful! These pickups are a lot hotter than the stock ones and give a very distinctive tone. But most importantly, they’re wired as split coils so there’s absolutely zero hum with one pickup soloed!

Of course, there’s always something. These pickups are taller than the stock ones, and they couldn’t be seated low enough to have the proper distance from the strings. I needed to rout out the body cavities deeper for them. But I don’t own a router, or a drill press, or anything that you should probably have to do this job right. But I was determined to handle this the way I’ve handled everything else on this project: fast, cheap and out of control. I found the most suitable bit I had on hand for my hand drill, and set to work removing wood. The end result was pretty ugly (and honestly, still not quite deep enough), but it’s hidden, and now things look and sound great!