What am I doing wrong
What am I doing wrong
nessinits
Posts: 86Questions: 27Answers: 0
I try to select the first row of the Datatable after init. It displays the right id with alert();, but doesn't select te first row as it suposed to do:
$('#wl_persons')
.on( 'init.dt', function () {
var table = $('#wl_persons').DataTable();
alert(table.data()[0]['wl_persons']['persons_id']);
table.row(0).node().click();
} )
.dataTable();
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Node gives you a dom element, not a jqury element so click will not workj
try $( table.row(0).node()).trigger("click");
Additionally you need to modify your selector slightly:
':eq(0)'
- i.e.That way the first row in the table will be selected regardless of sorting. Using
0
alone will select the first row that was read into the table.Allan
It does something, but not completely what I expected.
I doesn't automatically make the first row "selected". Even when I add an on click event on the <tr> it selects the row as it should following the css, but it doesn't fire the regular events. For example the status of the datatable doesn't display any selected rows (1 row selected).
What am I doing wrong?
Don't do it with an event handler.
From what I understand, you are trying to select the first row so do this http://jsbin.com/kowejop/edit?html,css,js,output
Agreed -
row().select()
is a better way to select the row.Allan