How do I fetch data for column cells of selected rows?

How do I fetch data for column cells of selected rows?

morcuttmorcutt Posts: 4Questions: 2Answers: 0
edited March 2016 in Free community support

I've installed the latest version of DataTables, added some of the extensions (buttons, select, etc.) and everything is working well, including the 'Select All' and 'Deselect All', buttons, Bootstrap formatting, etc. However, I'm at a loss as to how to fetch the data related to what rows have been selected. I need to pass the information to another page for server-side processing. I can see where I can do things like:

table.rows('.selected').data()

I could load that into a form field and submit the form via javascript, but I don't know what is contained in this object and I likely don't need all of the information as I don't need all of the tables data - I really just need data from a particular column cells (e.g. "User ID") for the selected rows.

Answers

  • morcuttmorcutt Posts: 4Questions: 2Answers: 0
    edited March 2016

    ok, I implemented a solution for this which likely could have been done simpler if I knew what I was doing, but it worked:

                                action: function ( e, dt, node, config ) {
                                    for (var i = 0; i < table.rows('.selected').data().length; i++) { 
                                       selectArray += table.rows('.selected').data()[i][0];
                                       if (i+1 < table.rows('.selected').data().length) {
                                           selectArray += ',';
                                       }
                                    }
                                    document.getElementById("selectedRows").value = selectArray;
                                    document.getElementById("frmViewCandidates").submit();
                                }
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 61,903Questions: 1Answers: 10,148 Site admin

    Hi,

    The way to do this is to use the selected option of the selector-modifier object - for example: table.rows( { selected: true } ).data().

    This, and other details for how Select integrates with the DataTables API are available on this manual page.

    Regards,
    Allan

This discussion has been closed.