OneTwo
OneTwo

Reputation: 2483

Make a row selected after adding it

I want it so that when I add a row to a datatable, that row will be selected (highlighted). So I remove the selected class from the currently selected row, but I don't know how to add the selected class to the new row.

Removes selected class from currently selected row.

$('#rListTable tr.selected').removeClass('selected');

Adds new row to table.

aTable.row.add(data.analysis).draw(false);

Upvotes: 0

Views: 75

Answers (2)

Pedro Ferreira
Pedro Ferreira

Reputation: 53

The table.row.add() returns an instance of the row you have just added. So to style that row you just need to select it like:

var rowAdded = aTable.row.add(data.analysis).draw(false);
$(rowAdded).addClass('selected');

Or you can simply do:

aTable.row.add(data.analysis).draw(false).nodes().to$().addClass('selected');

You can check the API

Upvotes: 1

collab-with-tushar-raj
collab-with-tushar-raj

Reputation: 1287

Add a row and get its newly created node to highlight that it was newly added:

 var rowNode = aTable.row.add(data.analysis).draw(false); //This will add the row 
 $( rowNode ).addClass('selected'); //This will highlight that newly added row

Regards

Upvotes: 0

Related Questions