Option to add a checkbox column to DataTables
Option to add a checkbox column to DataTables
joao
Posts: 2Questions: 0Answers: 0
Hello, I have a web application where I'm using DataTables to display server data, and I'd like to know if it's possible to create a feature that dynamically adds a checkbox column to the left of each row, as well as the header.
Currently, for each table that requires this functionality, I manually add the check all checkbox to the table header DOM, and an aoColumn with a checkbox as the default content. I've created a jsfiddle to demonstrate a very simplified version of this approach http://jsfiddle.net/UHuAK/.
Since I tend to repeat this code for each table that has this feature, I'd like to isolate it and create a new DataTables option/feature to activate it whenever I need it. Something along these lines:
[code]
$(document).ready(function() {
$('#example').dataTable({
"multipleSelection": true // this would add a new header column and a new data column for each row with a checkbox
});
});
[/code]
What I currently have is a wrapper (outside DataTables), that basically manipulates the DOM and the aoColumns array *before* I initialize dataTables, but I'd like to have this implemented as a feature within DataTables. My main problem here is that when the init callback of each feature is called, dataTables was already initialized, and I have to fill every internal structure for this to work (aoColumns, aoColSearch, etc.), but it just doesn't feel right to manipulate these internal structures.
Thanks in advance for any pointers you can provide.
Currently, for each table that requires this functionality, I manually add the check all checkbox to the table header DOM, and an aoColumn with a checkbox as the default content. I've created a jsfiddle to demonstrate a very simplified version of this approach http://jsfiddle.net/UHuAK/.
Since I tend to repeat this code for each table that has this feature, I'd like to isolate it and create a new DataTables option/feature to activate it whenever I need it. Something along these lines:
[code]
$(document).ready(function() {
$('#example').dataTable({
"multipleSelection": true // this would add a new header column and a new data column for each row with a checkbox
});
});
[/code]
What I currently have is a wrapper (outside DataTables), that basically manipulates the DOM and the aoColumns array *before* I initialize dataTables, but I'd like to have this implemented as a feature within DataTables. My main problem here is that when the init callback of each feature is called, dataTables was already initialized, and I have to fill every internal structure for this to work (aoColumns, aoColSearch, etc.), but it just doesn't feel right to manipulate these internal structures.
Thanks in advance for any pointers you can provide.
This discussion has been closed.
Replies
http://datatables.net/release-datatables/examples/server_side/select_rows.html
True, I sometimes forget the majority of our datatables usage is intranet only so I can just tell all the users to click the row if required.