Retrieve ID of DataTable Generated Server Side

Retrieve ID of DataTable Generated Server Side

mrfettmrfett Posts: 2Questions: 1Answers: 0

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

  • mrfettmrfett Posts: 2Questions: 1Answers: 0

    Sorry, new to this forum and forgot to mark my example html as code:

    <table>
    <tr id="product34"><td>blah</td></tr>
    <tr id="product334"><td>blah blah</td></tr>
    </table>
    
  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    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 of selector-modifier of { selected: true } loop through the selected rows. Use row().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

Sign In or Register to comment.