// I need to

ModernizeUpgrade without breaking it RescueFix what someone else started Build NewTurn an idea into a product Reach More PeopleGet found, get used, include everyone

// Company

Case StudiesExpertiseAbout + CareersResourcesContact Book a call →

Bootstrap Radio Buttons as DataTable Filters

Use Bootstrap radio buttons as clean, one-click filters for DataTables. Part 1 converts a classic radio input into a Bootstrap button group, with code.

Art+Logic Jun 6, 20162 min read

From the Art+Logic archive · written in 2016. The tools may have moved on; the thinking still holds.

Bootstrap Radio Buttons as DataTable Filters

This is the first of a series of tutorials on using Bootstrap radio buttons in the wild to filter real datasets in concert with other commonly-used UI components like DataTables and jQuery UI.

Part 1: Converting a classic input radio to the Bootstrap label

Photo by Dawid Zawiła on UnsplashFiltering tables of data is the central task of many a business web-app. DataTables are searchable by default, but records often beg to be batch-filtered into several status modes like: current | archived | all.

Bootstrap Radio Buttons provide a nice, clean look, but many developers shy away from them due to unfamiliarity with their CSS label-based class manipulation and/or compatibility issues with other component libraries like jQuery UI.

Bootstrap checkbox and radio btn-groups work ‘out of the box’, but the simple activation of a default button decouples active button highlighting from the input tag checked state. In this case, the active label class must be handled manually, but the docs don’t explain how, so a stack-overflow of posts for dev-help ensues.

How To: Bootstrap-style radio btn-group-ies

In this JSFiddle Example, you can view the de-coupled (broken) Bootstrap state by uncommenting the first line of the toggleActive method.

var toggleActive = function(activate)
{
   //return; // uncomment this line to see the de-coupled (broken) Bootstrap state
   // de-activate any existing selection
   $('#record-filters').find('.btn-primary').each(function(index, element) {
      $(element).removeClass('active');
   });
   activate.addClass('active');
}

Avoid jQuery UI conflicts:

Anyone who has delved into the wealth of threads asking whether Bootstrap and jQuery UI can be used together will quickly find that there are a range of answers from ‘yes, absolutely’ to ‘no, absolutely not’. As usual, the truth lies between the extremes.

Here are a few simple rules-of-thumb to avoid conflicts between Bootstrap and jQuery UI:

Parts 2 and 3 of this tutorial series will describe how to handle disabled radio-button state and how to co-ordinate dynamic sets of radio buttons on a single form.

keep going

More to explore in Reach More People.

All Reach More People resources →
let's talk

Got a problem like this one?

Tell us what's stuck. A real person replies within one business day.

Talk to our team →

Talk to people who know software, not a sales script.

Your first call is with Aja, our VP of Sales. He'll help make sure you're solving the right problem. Here's what you'll cover together:

  1. What you're trying to accomplish

    The business goal first, then the technology.

  2. Possible approaches

    And the tradeoffs of each, in plain language.

  3. Risks you may not have considered

    Technical and business, before they cost you.

  4. Whether AI changes the math

    What's practical, and what's just hype for your project.

  5. Sensible next steps

    Even if the right next step is not us.

book-a-call.ics

Loading the scheduler…

Open the booking page →

Some problems are easier to explain in writing. Send us a few lines about what you're working on, and we'll reply within one business day. Helpful to include:

  1. What the software does, or should do
  2. What's stuck, or what's worrying you
  3. Any deadline or budget you have in mind
note.md

Loading the form…