select first row onload
select first row onload
I'm trying to auto select first row of table when data is loaded for the first time and failing to do that.
How do I auto select first row of table when table loads for the first time? This html doesn't work:
[code]
<!DOCTYPE html>
@import "DataTables/css/demo_page.css";
@import "DataTables/css/demo_table.css";
var oTable;
var firstTime = true;
$(document).ready(function () {
$("#example tbody").click(function (event) {
$(oTable.fnSettings().aoData).each(function () {
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
oTable = $('#example').dataTable({
"sScrollX": "500px",
"sPaginationType": "full_numbers",
"bServerSide": true,
"sAjaxSource": "services/data3.ashx",
"sServerMethod": "POST",
"fnDrawCallback": function (oSettings) {
if (firstTime) {
alert('DataTables has redrawn the table');
oTable.$('tr:first').click();
firstTime = false;
}
}
});
});
id
name
surname
name
surname
id
[/code]
How do I auto select first row of table when table loads for the first time? This html doesn't work:
[code]
<!DOCTYPE html>
@import "DataTables/css/demo_page.css";
@import "DataTables/css/demo_table.css";
var oTable;
var firstTime = true;
$(document).ready(function () {
$("#example tbody").click(function (event) {
$(oTable.fnSettings().aoData).each(function () {
$(this.nTr).removeClass('row_selected');
});
$(event.target.parentNode).addClass('row_selected');
});
oTable = $('#example').dataTable({
"sScrollX": "500px",
"sPaginationType": "full_numbers",
"bServerSide": true,
"sAjaxSource": "services/data3.ashx",
"sServerMethod": "POST",
"fnDrawCallback": function (oSettings) {
if (firstTime) {
alert('DataTables has redrawn the table');
oTable.$('tr:first').click();
firstTime = false;
}
}
});
});
id
name
surname
name
surname
id
[/code]
This discussion has been closed.
Replies
Then all you need to do in fnInitComplete is add: `$('#example tbody tr:eq(0)').click();` .
Allan