I want to select a row from table without clicking. Instead of $('#myid').addClass('selected'); i want to use jquery like table.rows('#myid').select=true; However i don't know if it is such a use or not. Can you help me?
I need row select getting row id from binding column values of EmpId
EmpID Name
1 John
2 smith
4 Mark
myTable.rows('tr:eq(2)', { page: 'current' }).select(); it is default selecting 2nd row, but i want get row id of EmpID 1,4 and assign into eq(x) of row id, Please help
Answers
https://datatables.net/reference/api/row().select()
The https://datatables.net/reference/api/row().select()
does not work.
var table = $('#myTable').DataTable();
table.row(0).select();
I would of expected to select the 1st row of the table and add the selected class to the row, but it did nothing, nada, ziltch
I assume you are loading the select extension as mention in the doc for
row().select()
.I think
row(0)
will select the first row of the data as originally presented to Datatables, before sorting, etc.Are you expecting to select the first row displayed? Then you might try the example shown in the docs:
https://datatables.net/reference/api/row().select()#Example
Kevin
Thank you for your attention. I solved in following way;
I need row select getting row id from binding column values of EmpId
EmpID Name
1 John
2 smith
4 Mark
myTable.rows('tr:eq(2)', { page: 'current' }).select(); it is default selecting 2nd row, but i want get row id of EmpID 1,4 and assign into eq(x) of row id, Please help
Use the
row-selector
as a function rather than a string. You know the id in the data, so you can check against that in the function.If you link to an example on http://live.datatables.net or JSFiddle I can take a look at it.
Allan