We are pleased to introduce jQuery DataTables Checkboxes extension that makes it easy to add a checkbox columns to a table.
Example
Example below shows a data table using client-side processing mode where data is received from the server using Ajax.
Please visit dedicated jQuery DataTables Checkboxes page to download the code, view examples and documentation.
Figured it out. Should have google search more.
Thank you for great plugin and tutorial.
I have a question please . I need to post to my php script not only the ID but also
the Name and Office (in the example above) , what to change in the code please ?
Thank you!
Very useful indeed, but i need some help for a simple use case:
in my datatable i need to show some checkboxes as disabled (due some row item attributes) but the script override this option making every checkbox enabled (i can clearly see my disabled checkboxes turning enabled on the calling of initcomplete datatable event).
Is there a way to keep default checkbox enabled/disabled status?
Thanks in advance
Please see Disable checkboxes on page load example.
Great addition but I am running into a problem.
When I use your example, it works great. If I want to use my own table (generated from another system like a .net page, get the error:
As a proof of concept I took your example table and hardwired it into the html page as example2 and removed the ajax line:
Then simply changed
To my new table example2
With that example I get the same data when calling
When debugging,
rowData[2]
correctly matches'Software Engineer'
but the call tothis.api().cell(td).checkboxes.disable();
throws the errorAny insight would be appreciated.
Thanks,
Randy
Try using alternative solution suggested on this page. Apparently first solution only works for Ajax-sourced data.
See this example for code and demonstration.
Your support on a Sunday evening is fantastic. That is the inspiration I needed to move forward.
Thank you so much for such a great addon.
Randy
Thank you, Randy!
Hi Michel,when i only click on checkbox row should be selected,but when i click on anywhere in the row checkbox is getting clicked..can you help me with that
Please see Selection with checkboxes only example.
Hi Michel,in this example if i click anywhere in the row it selects the whole row,but i need, when i click only on checkbox it should select the row.Thanks
Naresh,
There was another example on that page titled “Selection with checkboxes only” which does what you need.
Hi!
when I try to check rows_selected I get the console error:
“table_cards.columns is not a function” ???
I am using:
var rows_selected = table_cards.column(0).checkboxes.selected();
where table_cards is the var name of the actual table where the data is build from a mysql table.
best greetings
Most likely the reason is that you use
dataTable()
instead ofDataTable()
to initialize DataTables plug-in.After reinitialize table
Error occurred on checkbox click : cellIdx is undefined; can’t access its “column” property
Hi! Thank you for this helpful datatables plug-in!
I’m storing selected rows in a database/local storage. When I was looking for a way how to load the stored checkboxes into the table, I found many way to do it in “pure” datatables, without checkboxes plug-in. None of those worked. How can I do this?
I can identify the checkboxes by id:
The function is called on document.ready
How can I do this?
Thanks in advance,
Please see Select checkboxes on page load example.
Thank Michael, I have seen this example. It selects the checkboxes based on another table column, but I didn’t know how to select checkboxes based on an “external” array.
Now I came up with this solution:
It may not be the most elegant solution as it iterates over the whole table, but at least it now it works 🙂
This is absolute gold! Is there a risk that the github repository will be taken down? As in, should I download the source code and maintain a copy?
Repository will be always available unless GitHub goes down. As an alternative you can download the source code and host source files on your own server.
How to select all for per page?
Use columns.checkboxes.selectAllPages option and set it to
false
to select checkboxes on current page only. For example:hi
how remove single row or all row table?
Hi Michael,
When I click on checkbox the checkbox is checked, but row is not selected, when I click anywhere else on the row the row is selected bu checkbox is not. Can you help me with this please?
This is the piece of code I’m using:
What browser are you seeing this issue with? Can you replicate this issue with Chrome or Firefox? Can you create a test case on jsfiddle.com?
I am using the latest version of Google Chrome. This is my fiddle:
https://jsfiddle.net/xpvt214o/994471/
Thanks!
There is a typo in your code, use
'selectRow': true
instead.Thanks for your fast reply, corrected that one, now it selects the line when I press the checkbox, but it does not select the checkbox when I press anywhere else on the line instead of checkbox cell.
It works for me, see this example.
I have recently replaced my datatable library
https://cdn.datatables.net/v/dt/dt-1.10.16/sl-1.2.5/datatables.min.js
With
https://cdn.datatables.net/v/dt/dt-1.10.18/r-2.2.2/datatables.min.js
Checkboxes continues to work except it does not highlight the row when selected. I have also changed the corresponding css.
This example, https://jsfiddle.net/gyrocode/snqw56dw/ works but when i replace the .js with the new version the rows don’t highlight.
Any suggestions?
Thanks,
Randy
Try including Select extension as well. For example, https://cdn.datatables.net/v/dt/dt-1.10.18/r-2.2.2/sl-1.2.6/datatables.min.js and https://cdn.datatables.net/v/dt/dt-1.10.18/r-2.2.2/sl-1.2.6/datatables.min.css.
Hi;
I would like to select or unselect rows manually. For example; on my table, column 2 holds the “scores” data. I would like to select rows, that has score data higher than 100 and unselect the others. May be a for loop or something for solution. Thanks for your great codes…
Hi! i have two things and are related i want to do this
on select/check -> check regarding data from the selected row if can be checked or not (example Users check – on callback if one of the columns has the need value can be checked if not should show an alert or something saying that cannot be checked)
Hi,
I tried to use the ‘Select checkboxes on page load’ example on a DOM-data-source, but it looks like I am to ‘early’ here, since the input-checkbox isn’t generated at that moment the ‘createdCell’- callback is started. Is there a work around for this?
Marcel, there is an alternative solution you could try if you’re using deferred rendering but it only makes sense with Ajax or JavaScript data sources. However I think there is something else involved. If you can create a reproducible example, that would help to investigate.
Hello Michael,
Thanks for your quick reply!!
I just saw a previous question which also pointed to this alternative solution, and I just tried it… and it worked with that one!!
So this alternative solution is also good for DOM(html) sources.
Thank you!
Hi,
I tried to put a limit on the selection of check but i couldn’t.Is there any solution implemented for this?
Thanks in advance.
Cristina, currently there is no example or built-in support for that but since there are other similar requests, I may look into implementing that.
Hello Michael,
Have you gone into implementing this?
Thanks.
Hi Michael,
First of all. Thanks for this amazing plug-in.
I have a scenario where we have more than 20,000 records to display via ajax call, and we have pagination at place as well for this. but when we are doing “Select All” Checkbox then records only on the current page are getting checked , but other records on remaining pages are not getting checked, though they are getting selected.
we have a requirement where we want to show the individual checkboxes of all the records across the pages should be in checked state when we click on “global select all” checkbox.
Your advise will be really helpful.
Thanks In advance.
Hi!
How can I get the number of checkboxes selected?
Hi, I want all checkbox selected in data table?
Thanks its very interesting.
Can you you send source code please.
Thank you.