Note that there are some explanatory texts on larger screens.

plurals
  1. POdatatables select first row onload
    primarykey
    data
    text
    <p>I'm trying to auto select first row of table when data is loaded for the first time and failing to do that.</p> <p>How do I auto select first row of table when table loads for the first time? This html doesn't work:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;style type="text/css" title="currentStyle"&gt; @import "DataTables/css/demo_page.css"; @import "DataTables/css/demo_table.css"; &lt;/style&gt; &lt;script type="text/javascript" src="Datatables/js/jquery.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="Datatables/js/jquery.dataTables.js"&gt;&lt;/script&gt; &lt;script&gt; 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; } } }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;table border="1" &gt; &lt;tr&gt;&lt;td&gt;id&lt;/td&gt;&lt;td&gt;&lt;input type="text" /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;name&lt;/td&gt;&lt;td&gt;&lt;input type="text" /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td&gt;surname&lt;/td&gt;&lt;td&gt;&lt;input type="text" /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt;&lt;br /&gt; &lt;table id="example" border="1" class="display"&gt; &lt;thead&gt; &lt;tr&gt; &lt;td&gt;name&lt;/td&gt; &lt;td&gt;surname&lt;/td&gt; &lt;td&gt;id&lt;/td&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt;&lt;/tbody&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload