I am coding in asp mvc and I am trying to implement the table of DataTables but I get this error: DataTables warning: table id=abc - Incorrect column count. For more information about this error, please see
This is my table:
<table id="abc" class="display table-bordered table-hover">
<tr>
<th>
@Html.DisplayNameFor(model => model.StudentID)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.Program)
</th>
<th>
@Html.DisplayNameFor(model => model.YearGraduate)
</th>
<th>
@Html.DisplayNameFor(model => model.BoardScore)
</th>
<th>Action</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.StudentID)
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Program)
</td>
<td>
@Html.DisplayFor(modelItem => item.YearGraduate)
</td>
<td>
@Html.DisplayFor(modelItem => item.BoardScore)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.StudentID }, new { @class = "btn btn-primary" })
@Html.ActionLink("Details", "Details", new { id = item.StudentID }, new { @class = "btn btn-success" })
@Html.ActionLink("Delete", "Delete", new { id = item.StudentID }, new { @class = "btn btn-danger" })
</td>
</tr>
}
</table>
I am coding in asp mvc and I am trying to implement the table of DataTables but I get this error: DataTables warning: table id=abc - Incorrect column count. For more information about this error, please see http://datatables/tn/18
This is my table:
<table id="abc" class="display table-bordered table-hover">
<tr>
<th>
@Html.DisplayNameFor(model => model.StudentID)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.Program)
</th>
<th>
@Html.DisplayNameFor(model => model.YearGraduate)
</th>
<th>
@Html.DisplayNameFor(model => model.BoardScore)
</th>
<th>Action</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.StudentID)
</td>
<td>
@Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Program)
</td>
<td>
@Html.DisplayFor(modelItem => item.YearGraduate)
</td>
<td>
@Html.DisplayFor(modelItem => item.BoardScore)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.StudentID }, new { @class = "btn btn-primary" })
@Html.ActionLink("Details", "Details", new { id = item.StudentID }, new { @class = "btn btn-success" })
@Html.ActionLink("Delete", "Delete", new { id = item.StudentID }, new { @class = "btn btn-danger" })
</td>
</tr>
}
</table>
Share
Improve this question
asked Nov 17, 2022 at 14:25
young gnupyoung gnup
451 gold badge1 silver badge3 bronze badges
3
- 1 what does your datatable initialization in javascript look like, also you seem to miss <thead> and <tbody> – Roe Commented Nov 17, 2022 at 14:28
- You can read the DataTables installation guide, which includes a section describing how to provide the HTML table structure required by DataTables. – andrewJames Commented Nov 17, 2022 at 18:14
- This is also covered in the page mentioned in your error message: Incorrect column count. Did you follow the resolution guidelines provided there? – andrewJames Commented Nov 17, 2022 at 18:16
4 Answers
Reset to default 9Your table is incorrect you are missing <thead> and <tbody> tags.
this is a valid table:
<table>
<thead>
<tr>
<th>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
</td>
</tr>
</tbody>
</table>
In my case the problem was the mand columnDefs.targets .
I remove this mand, and the error solve
If the number of <th>
tags is not equal to the number of <td>
tags , this error can also be for this reason
I had the same problem and i realised i had two in my tbody. So i think this error occurs either number of columns defined by the header and used in the body is not equal. Or you have some problem in the definition of table.