Using jQuery selector to get every row in datatable?

Using jQuery selector to get every row in datatable?

ahcahc Posts: 5Questions: 3Answers: 0

If the last cell of every row in my table has the same class attribute (ex. <td class="myClass" >), and I try to select all of these cells using the jQuery selector $('.myClass'), the resulting array only contains the cells that are currently being displayed on the page, leaving out the ones that exist on other pages of the datatable.

Is there a way to make it so that this selector will return every element in the table, not just the elements on the current page of the table? If not, what would be the best way to accomplish the same task in a different manner.

Thanks.

Replies

  • allanallan Posts: 63,602Questions: 1Answers: 10,486 Site admin

    As DataTables removes nodes form the document that aren't needed for display, you would need to use the DataTables API.

    Specifically you could use the cells().nodes() method or column().nodes() (which would be faster if you know which column is being used):

    table.column( -1 ).nodes().to$()
    

    will give you a jQuery object with the cells from the last column in the table.

    Allan

This discussion has been closed.