Solved

How do I select all table rows using a checkbox in the header using Jquery datatable tabletools?

Posted on 2014-04-23
3
14,064 Views
Last Modified: 2014-05-04
New to JQuery.
Thanks.
0
Comment
Question by:RSSY
3 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 40020199
One way would be to use the aoColumns property of datatables and just render your markup for the "sTitle" property as an html string.

http://www.datatables.net/usage/columns

//On datatable init the options would look something like this
"aoColumns": [{   "sTitle": "<input type='checkbox' id='selectAll'></input>"}]
Then you could just wire up a handler to the header checkbox after the datatable is created to check/uncheck all the checkboxes;

So something like:

$("#selectAll").toggle(function () {
       $("checkboxSelector", dataTable.fnGetNodes()).attr("checked", true); }
     , function () {
         $("checkboxSelector", dataTable.fnGetNodes()).attr("checked", false);
     }
 );
0
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
ID: 40020225
Since you don't have any code to work with, then I will leave it up to you to integrate this code below into yours:

<script type="text/javascript">
$('#checkall').click( function() {
$('input', oTable.fnGetNodes()).each( function() {
$('input', oTable.fnGetNodes()).attr('checked','checked');
} );
return false; // prevent page refresh
} );
</script>

Open in new window


//markup
<form id="checkall"><input type="submit"/></form>

Open in new window

0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question