Correct table structure (noob question)
Correct table structure (noob question)
I have an auto-generated table that gets created after a jQuery ajax call returns a json payload.
The table gets created with javascript and displays ok (although ugly) without any formatting.
The code I was using to generate the table from json was not adding any <tbody> tags and when I added $('#resultsTable').DataTable(); to my script I got the message "Showing 0 to 0 of 0 entries".
So I modified the script to add the <tbody> tags but now when I hit the $('#resultsTable').DataTable(); line I get an alert from DataTables saying "DataTables warning: table id=resultsTable - Incorrect column count.".
So here is my generated table markup. Can anyone spot what my problem is? the <colgroup> tags are kind of weird because I'm not explicitly adding them. Maybe the browser (Chrome) does that?
<table id="resultsTable" class="dataTable">
<colgroup></colgroup>
<tr><th>vendor_id</th><th>full_name</th><th>date_time</th></tr>
<tbody>
<tr><td>1</td><td>Frogville Records</td><td>2019-08-26T04:34:52.193</td></tr><tr><td>3</td><td>URP Music Distributors</td><td>2019-08-26T09:05:26.593</td></tr>
<tr><td>4</td><td>Monostereo</td><td>2019-08-26T09:06:46.78</td></tr>
<tr><td>5</td><td>Isotope Music</td><td>2019-08-26T09:07:17.81</td></tr>
<tr><td>6</td><td>PEZ</td><td>2019-08-27T20:06:48.347</td></tr>
</tbody>
</table>
Replies
The problem might be the missing
thead
tag for the header. See the HTML requirements doc for details. See this working test case with your HTML and the addedthead
:https://live.datatables.net/kayeqito/1/edit
Kevin
Thanks! That was it. I had a bug in my table generator that was leaving that out.