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 9298529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:20:53+00:00 2026-06-18T22:20:53+00:00

I have inherited the following code: // Show / Hide table rows from checkboxes

  • 0

I have inherited the following code:

  // Show / Hide table rows from checkboxes
  $("table.data#report-table .warning").toggle($("#warning_checkbox").is(":checked"));
  $("#warning_checkbox").click(function() {
    $("table.data#report-table .warning").toggle($("#warning_checkbox").is(":checked"));
    $('.data_table#report-table').dataTable().fnDraw();
  });

When a checkbox with id warning_checkbox is checked, it shows/hides the rows (actually, tbody elements) of table.data#report-table which have the class .warning

As far as i can see, there is no '.data_table#report-table element on the page – so i assumed something wouldnt work. However – it (magically?) does, i.e. the table is redrawn as expected, preserving its correct settings. I do however get the following error in the Chrome console:

Uncaught TypeError: Cannot read property 'oFeatures' of null 

Which i thought may be due to the missing element (but then how does it still work?) Anyway, i rewrote the code as a function as i need to reuse it elsewhere:

  var checkbox_rows = function(checkbox_id, table_id, tbody_class) {
    var checkbox = $('div.buttons input[id$='+checkbox_id+']');
    var table = $('table.data[id$='+table_id+']');

    checkbox.click(function() {
      $('tbody[class$='+tbody_class+']', table).toggle(checkbox.is(':checked'));
      table.fnDraw();
    });
  }

  checkbox_rows('warning_checkbox', 'report-table', 'warning');

This also works (and makes more sense to me) – but now i get a different error in the Chrome Console:

Uncaught TypeError: Object [object Object] has no method 'fnDraw'

So my question is, what am i doing wrong? What is the correct way to redraw a DataTable?

Thank you

  • 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-06-18T22:20:54+00:00Added an answer on June 18, 2026 at 10:20 pm

    In your modified code, you’re calling fnDraw() on the jQuery $('table') object — which has no associated fnDraw() method — instead of the DataTable object.

    You’ll want to call fnDraw() on the object you originally call dataTable() on, as in:

    $(document).ready(function() {
      var oTable = $('#yourDataTable').dataTable();
      oTable.fnDraw();
    });
    

    So this wouldn’t work:

    $(document).ready(function() {
      var oTable = $('#yourDataTable');
      oTable.fnDraw(); // Won't work, because the dataTable() method wasn't called above
    });
    

    If you can’t access the original object you called dataTable() on any more for some reason (difficult to say without seeing more of your code), you could try reinitializing the table by calling dataTable() on table and optionally passing in bDestroy or bRetrieve, depending on what you need. So something like:

    table.dataTable({ "bRetrieve": true });
    

    (I’m honestly not sure whether you’d need to call fnDraw() any more after that.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code (inherited from someone): <div class=feedback>&nbsp;</div> <form onsubmit=return false autocomplete=off>
I have the following code in specman that I inherited: some_method() is { var
Code which I have inherited keeps crashing out rather powerfully with the following error
I want to hide master page table from the content page. I have tried
I have just inherited some code and part of that code is to show
I have inherited the following code snippet: <div id=topbox> <h3> <div class=compare_link>Compare Products</div> <input
I have the following code (inherited!) that will split a line of text into
I have inherited a project that uses the following pattern for passing parameters from
Please have a look at the following code Code to insert data package com.example.esoftcallmanager;
I have defined an Event class: Event and all the following classes inherit from

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.