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,322 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

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

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

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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

807 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