How to use row-selector with ID to get one row from jQuery Datatables?

How to use row-selector with ID to get one row from jQuery Datatables?

florinsecalflorinsecal Posts: 2Questions: 1Answers: 0

I am trying to select one specific row from a jQuery Datatables using the row-selector with the ID in string format.

The Id's for each row are assigned using DT_RowId from a JSON server by the server.

<tr id="row-404" role="row" class="odd">
<td class="text-nowrap">404</td>
<td>Some random columns</td>
</tr>
I cannot get the row to be selected using the following script:

var table = $("#datatable");
if ($.fn.DataTable.fnIsDataTable(table)) {
table = table.DataTable();
var rowSelector = "row-404";
var row = table.row(rowSelector);
var data = row.data();
console.log(data);
}
I manged to get the some rows using other selectors (example: the jQuery selector), but since I am using pagination, they do not work if your row is on another page.

Answers

  • Tom (DataTables)Tom (DataTables) Posts: 139Questions: 0Answers: 26
    edited May 2016

    Hi Florinsecal

    var rowSelector = "row-404"; 
    

    should be

    var rowSelector = "#row-404";
    
    

    If you want more information on using row-selector then please refer to the documentation for row-selector,

This discussion has been closed.