Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6804793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:30:34+00:00 2026-05-26T19:30:34+00:00

I have prepared a simple test case for my question. Just save it to

  • 0

I have prepared a simple test case for my question.

Just save it to a disk and open in the browser – it will work instantly, you don’t have to download or install anything.

Here is the screenshot for my test case:

screenshot

My question is: how could I filter the rows in the table, when the user selects fruit and/or candy? What function to call here, fnDraw()?

My test file index.html:

<html>
<head>
<style type="text/css" title="currentStyle">
        @import "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/redmond/jquery-ui.css";
</style>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/DataTables/DataTables/master/media/js/jquery.dataTables.js"></script>
<script type="text/javascript">

$(function() { 
        var my_table = $('#my_table').dataTable( {
            bJQueryUI: true,
            aoColumns: [
                /* type */ { bVisible: false, bSearchable: false },
                /* thing */ null
            ]
        });

        $(':checkbox').click(function() {
            alert('XXX what to do here? XXX');
        });
});

</script>
</head>
<body>

<p>What should be shown:</p>
<p><label><input type="checkbox" value="fruit">fruit</label></p>
<p><label><input type="checkbox" value="candy">candy</label></p>

<table id="my_table">
<thead>
<tr>
<th>Type</th>
<th>Thing</th>
</tr>
</thead>
<tbody>
<tr><td>fruit</td><td>apple</td></tr>
<tr><td>fruit</td><td>banana</td></tr>
<tr><td>fruit</td><td>pear</td></tr>
<tr><td>candy</td><td>jelly</td></tr>
<tr><td>candy</td><td>toffee</td></tr>
<tr><td>candy</td><td>fudge</td></tr>
</tbody>
</table>
</body>
</html>

Thank you for any hints!

UPDATE: I’ve asked at the DataTables forum too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:30:34+00:00Added an answer on May 26, 2026 at 7:30 pm

    Here is my own solution using afnFiltering, it works well.

    I didn’t like fbas’ solution using fnFilter, because this causes the search string to be displayed in the search field. (But still thanks for your suggestion).

    <html>
    <head>
    <style type="text/css" title="currentStyle">
            @import "http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/redmond/jquery-ui.css";
    </style>
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
    <script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.2/jquery.dataTables.min.js"></script>
    <script type="text/javascript">
    
    $.fn.dataTableExt.afnFiltering.push(
            function(oSettings, aData, iDataIndex) {
                    var isFruit = (aData[0] == 'fruit');
                    return (isFruit ? $('#fruit').is(':checked') :
                                      $('#candy').is(':checked'));
            }
    );
    
    $(function() { 
            var my_table = $('#my_table').dataTable( {
                    bJQueryUI: true,
                    aoColumns: [
                            /* type */  { bVisible: false, 
                                          bSearchable: false },
                            /* thing */ null
                    ],
    
            });
    
            $(':checkbox').click(function() {
                    my_table.fnDraw();
            });
    });
    
    </script>
    </head>
    <body>
    
    <p>What should be shown:</p>
    <p><label><input type="checkbox" id="fruit">fruit</label></p>
    <p><label><input type="checkbox" id="candy">candy</label></p>
    
    <table id="my_table">
    <thead>
    <tr>
    <th>Type</th>
    <th>Thing</th>
    </tr>
    </thead>
    <tbody>
    <tr><td>fruit</td><td>apple</td></tr>
    <tr><td>fruit</td><td>banana</td></tr>
    <tr><td>fruit</td><td>pear</td></tr>
    <tr><td>candy</td><td>jelly</td></tr>
    <tr><td>candy</td><td>toffee</td></tr>
    <tr><td>candy</td><td>fudge</td></tr>
    </tbody>
    </table>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have prepared a simple test case demonstrating my problem. It is just 1
I have a very general question and have prepared a simple test case. When
I have a pure ActionScript 3 problem, but the simplified test case I've prepared
I have prepared a code to just play a simple mp4 file from my
I am preparing a simple dictionary project and I have prepared it to search
I have the following simple mysqli php application, which should work fine. $pk is
I have a very simple PHP form, which shows a checkbox, and will store
I have a simple RESTful web service and I wish to test the PUT
I save a video, test.mp4 , in my project's res/raw directory. I have my
Simple performance test, I have installed ruby-prof and no other gems are missing, rake

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.