![](/img/trans.png)
[英]Problem updating jquery dataTables plug-in with ASP.NET MVC
[英]jQuery Datatables plug-in not working with ASP.NET MVC
我正在嘗試使用 jquery 數據表插件向我的 MVC 應用程序中的表添加更多功能。 我已將以下內容添加到我的 index.cshtml 頁面,以嘗試將表“dailyreporttable”從標准表轉換為數據表:
<script src="~/Scripts/DataTables-1.9.4/media/js/jquery.dataTables.js" type="text/javascript"></script>
<script src="~/Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#dailyreporttable').dataTable();
});
</script>
但是當我在瀏覽器中預覽頁面時,datatables plus in 並沒有應用到表格中,它仍然是標准表格。 我沒有任何 MVC 或 Web 開發經驗,所以我不確定我到底做錯了什么。
您應該將這些引用添加到您的 BundleConfig.cs 文件中。
您可能會在 _Layout.cshtml 中加載一個包:
@Scripts.Render("~/bundles/myBundle")
因此,將 jquery 和 datatables 引用添加到該特定包中,例如:
bundles.Add(new ScriptBundle("~/bundles/myBundle").Include(
"~/Scripts/jquery-1.10.2.min.js"
"~/Scripts/DataTab....ataTables.js"
));
您可以通過查看 Firebug Net 選項卡來檢查 js 文件是否正在加載(如果您使用的是 Firefox)
你有對css文件的引用嗎? rel="stylesheet" type="text/css" href="../../media/css/jquery.dataTables.css"
嘗試更改腳本加載順序:
<script src="~/Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="~/Scripts/DataTab....ataTables.js" type="text/javascript"></script>
由於datatables
的jQuery基於插件,它需要jQuery方法來運行,所以你必須包括jQuery庫首先使所有所需的方法獲取提供給datatable
插件。
<head>
<script src="~/Scripts/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="~/Scripts/DataTables-1.9.4/media/js/jquery.dataTables.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#dailyreporttable').dataTable();
});
</script>
</head>
<body>
<table id="dailyreporttable">
</table>
</body>
https://datatables.net/examples/basic_init/zero_configuration.html
$('#dailyreporttable').dataTable();
只需將其移出 document.ready()
這似乎對我有用,
另一種方法是使用 ClientID
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.