Option to add a checkbox column to DataTables

Option to add a checkbox column to DataTables

joaojoao Posts: 2Questions: 0Answers: 0
edited June 2012 in DataTables 1.9
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.

Replies

  • snarf2larfsnarf2larf Posts: 64Questions: 0Answers: 0
    A little off topic but I was using checkboxes in my tables and switched to user selectable rows. I believe this is much easier for the user than checkboxes. You get the extra space and the user doesn't have to be so precise with their clicking.

    http://datatables.net/release-datatables/examples/server_side/select_rows.html
  • joaojoao Posts: 2Questions: 0Answers: 0
    Indeed, it has some advantages. However, on most applications that I've worked on, I found out that users do not know that a row is clickable, unless you have an explicit checkbox (it's just the way they are used to work). I actually have a mixed implementation, where the user can either click the checkbox, or click the row to select it, just like in the example you've shown.
  • snarf2larfsnarf2larf Posts: 64Questions: 0Answers: 0
    [quote]joao said: Indeed, it has some advantages. However, on most applications that I've worked on, I found out that users do not know that a row is clickable, unless you have an explicit checkbox (it's just the way they are used to work). I actually have a mixed implementation, where the user can either click the checkbox, or click the row to select it, just like in the example you've shown.[/quote]

    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.
This discussion has been closed.