Retrieve ID of DataTable Generated Server Side
Retrieve ID of DataTable Generated Server Side
Hi all,
Apologies for the simple question here but I'm really struggling. I have an application whose tables are generated server side and just initiated as a datatable using a simple declaration that also enabled the select plugin:
    var dataTableObj = $('#dataTableWithCheckbox').DataTable({
        columnDefs: [
            {
                render: DataTable.render.select(),
                targets: 0
            }
        ],
        select: {
            style: 'os',
            selector: 'td:first-child'
        },
        order: [[1, 'asc']]
    });
The HTML has an id hard-coded per row (used for various other functionality), for example:
| blah | 
| blah | 
The select functionality is working great, all I now want to do is to be able to is execute a function that counts the number of selected rows and created a comma seperated list of those ideas.
Unfortunately it seems that most of the functionality is geared towards tables created with JavaScript. I read all the various forum posts I can find but no-one seems to be trying to just access hardcoded row IDs.
I've tryed many variations of looping through rows captured with this:
var dtRows = dataTableObj.rows( { selected: true } );
Any pointers would be much appreciated!
Answers
Sorry, new to this forum and forgot to mark my example html as code:
For most things the data source, HTML, Javascript or Ajax, does affect how Datatables works.
Use
rows().every()to loop through all the rows or in the case ofselector-modifierof{ selected: true }loop through the selected rows. Userow().id()to get the ID of the row. Here is a simple example based on your above code:https://live.datatables.net/huqutala/1/edit
Kevin