Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Hi You need to Create HTML Table from JSON Result : </p> <pre><code>function CreateDynamicTable(objArray) { //var array = JSON.parse(objArray); var array = objArray; var str = '&lt;table class="display" cellpadding="0" cellspacing="0" border="0" id="example"&gt;'; str += '&lt;thead&gt;&lt;tr&gt;'; for (var index in array[0]) { str += '&lt;th scope="col"&gt;' + index + '&lt;/th&gt;'; } str += '&lt;/tr&gt;&lt;/thead&gt;'; str += '&lt;tbody&gt;'; for (var i = 0; i &lt; array.length; i++) { str += (i % 2 == 0) ? '&lt;tr class="gradeA"&gt;' : '&lt;tr class="gradeA"&gt;'; for (var index in array[i]) { str += '&lt;td&gt;' + array[i][index] + '&lt;/td&gt;'; } str += '&lt;/tr&gt;'; } str += '&lt;/tbody&gt;' str += '&lt;tfoot&gt;&lt;tr&gt;'; for (var index in array[0]) { str += '&lt;th scope="col"&gt;' + index + '&lt;/th&gt;'; } str += '&lt;/tr&gt;&lt;/tfoot&gt;'; str += '&lt;/table&gt;'; return str; </code></pre> <p>}</p> <p>Script to create Datatable</p> <pre><code>$.ajax({ type: 'POST', url: '/Index/Patient', contentType: 'application/json; charset=UTF-8', dataType: 'json', success: function (data) { if (data != null) { var objlist = JSON.parse(data); //if no Data if (objlist.toString() != '') { var str = CreateDynamicTable(objlist ); //Create HTML Table in DIV $("#bind").html(str); //Create datatable $('#example').dataTable({ "sPaginationType": "full_numbers" }); } else { //if no Data } } } }); </code></pre> <p>And Your HTML :</p> <pre><code>&lt;div id="bind"&gt; &lt;table width="100%" id="patients"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;First Name&lt;/th&gt; &lt;th&gt;Last Name&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;/tbody&gt; </code></pre> <p> </p>
 

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