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,750 Views
Last Modified: 2014-05-04
New to JQuery.
Thanks.
0
Comment
Question by:RSSY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 29

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

Don't Miss ATEN at InfoComm 2017!

Visit booth #2167 to see the  new ATEN VM3200 32 x 32 Modular Matrix Switch. Other highlights include the VE8950 4K HDMI Over IP Extender, VS1912 12-Port DP Video Wall Media Player  and VK2100 ATEN Control System. Register now with Free Pass Code ATEN288!

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

751 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