I'm trying to make a website with asp.net mvc 4 & EF6 where user can use sorting, paging & filtering from client side for a table. I'm using DataTables 1.10.4
jQuery plugin for these functions. So far everything loaded perfectly but if I click on the <th>
content, columns not get sorting, whatever I type on the filter box, filtering is not working. I don't see any error in my browser console. Here are my codes,
Controller
public ActionResult UserLogin()
{
if (Session["UserNAME"] != null)
{
var mkimodel = new MkistatVsUserLogin { mkistats = db.mkistats.ToList() };
return View(mkimodel);
}
else
{
return RedirectToAction("Home");
}
}
View
<table id="mktTable" class="table">
<thead>
<tr>
<th>CodeName</th><th>% Change</th><th>High Price</th><th>Open Price</th><th>Total Value</th>
</tr>
</thead>
@foreach (var item in Model.mkistats)
{
<tbody>
<tr>
<td>
@Html.DisplayFor(modelItem => item.MKISTAT_CODE)
</td>
<td>
5%
</td>
<td>
@Html.DisplayFor(modelItem => item.MKISTAT_HIGH_PRICE)
</td>
<td>
@Html.DisplayFor(modelItem => item.MKISTAT_OPEN_PRICE)
</td>
<td>
@Html.DisplayFor(modelItem => item.MKISTAT_TOTAL_VALUE)
</td>
</tr>
</tbody>
}
</table>
_Layout.cshtml
<head>
<link href="~/Content/jquery.dataTables.css" rel="stylesheet" />
</head>
<body>
<script src="~/Scripts/jquery-1.9.1.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/DataTables-1.10.4/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$('#mktTable').DataTable();
});
</script>
@RenderBody()
@RenderSection("scripts", required: false)
</body>
Is there something wrong in my code? How can I make dataTables
work? Need this help badly. Tnx.
alert
in your js and check whether your javascript code is working or not