Note that there are some explanatory texts on larger screens.

plurals
  1. POshowing a different datatable on button click
    primarykey
    data
    text
    <p>hi i am creating an application with two tables one for student results and another one for student contacts i am using datatables to display the data. when the document loads the student results table is showing perfectly i have a button that when clicked should replace the student results table and show the student contacts table i have tried the solution below it is not working</p> <p><strong>jQuery</strong></p> <pre><code>$(document).ready(function() { var otable = $('#student_results').datatable({'sAjaxSource': "server.php"}); $("button#contacts").click(function(){ $("div #results table").replaceWith('&lt;table cellpadding="0" cellspacing="0" border="0" class="display" id="example"&gt; &lt;thead&gt; &lt;tr&gt;&lt;th width="5%"&gt;id&lt;/th&gt;&lt;th width="35%"&gt;name&lt;/th&gt; &lt;th width="30%"&gt;number&lt;/th&gt; &lt;th width="30%"&gt;department&lt;/th&gt;&lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt;&lt;td colspan="3" class="dataTables_empty"&gt;Loading data from server&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;tfoot&gt;&lt;tr&gt;&lt;th width="5%"&gt;id&lt;/th&gt;&lt;th width="35%"&gt;name&lt;/th&gt; &lt;th width="30%"&gt;number&lt;/th&gt;&lt;th width="30%"&gt;department&lt;/th&gt;&lt;/tr&gt; &lt;/tfoot&gt; &lt;/table&gt;'); example.fnReloadAjax('server_processing.php'); }); }); </code></pre> <p><strong>HTML</strong></p> <pre><code>&lt;div id="results"&gt; &lt;br/&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;button id="Result"&gt;Results&lt;/button&gt; &lt;button id="contacts"&gt;Contacts&lt;/button&gt; &lt;table cellpadding="0" cellspacing="0" border="0" class="display" id="example"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th width="2%"&gt;result_id&lt;/th&gt; &lt;th width="20%"&gt;reg_no&lt;/th&gt; &lt;th width="30%"&gt;name&lt;/th&gt; &lt;th width="15%"&gt;unit code&lt;/th&gt; &lt;th width="30%"&gt;unit title&lt;/th&gt; &lt;th width="3%"&gt;grade&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;br&gt; &lt;tr&gt; &lt;td colspan="3" class="dataTables_empty"&gt;Loading data from server&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;tfoot&gt; &lt;tr&gt; &lt;th width="2%"&gt;result_id&lt;/th&gt; &lt;th width="20%"&gt;reg_no&lt;/th&gt; &lt;th width="30%"&gt;name&lt;/th&gt; &lt;th width="15%"&gt;unit code&lt;/th&gt; &lt;th width="30%"&gt;unit title&lt;/th&gt; &lt;th width="3%"&gt;grade&lt;/th&gt; &lt;/tr&gt; &lt;/tfoot&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p>please help.</p>
    singulars
    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.
    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