I have a problem with bundling dataTables library. This is what I've got now:
//other bundles (bootstrap etc.)
bundles.Add(new ScriptBundle("~/bundles/datatables").Include(
"~/Scripts/jquery.dataTables.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/DataTables/css/dataTables.bootstrap.css",
"~/Content/DataTables/css/jquery.dataTables.css"));
and in _Layout.cshtml :
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link href="~/Content/fontawesome-all.min.css" rel="stylesheet" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<head>
...
</head>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/datatables")
@RenderSection("scripts", required: false)
Unfortunately it doesn't work, table is not modified. Another issue is that when I press F12 to inspect my website I don't see Scripts/datatables
attached on the end, only this:
<script src="/Scripts/jquery-3.5.1.js"></script>
<script src="/Scripts/bootstrap.js"></script>
additionally I can see th error: Uncaught TypeError: $(...).DataTable is not a function at HTMLDocument....
my JS looks like this:
$('document').ready(function () {
$('#myTable').DataTable({
"order": [[3, "desc"]]
});
});
Your /Scripts/jquery.dataTables.js
file does not seem to be loading. That is why you see the error on the console.
Can you try to load the datatable library with <script src="/Scripts/jquery.dataTables.js"></script>
referance instead of the existing @Scripts.Render("~/bundles/datatables")
?
Also you seem to be loading jquery library twice!?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.