一、 我按照這里給出的說明來設計cshtml頁面,https://github.com/Mobius1/Vanilla-DataTables
我已經(jīng)適當?shù)靥砑恿薈SS和JS文件,
CSS
<link rel="stylesheet" type="text/css">
JS
<script src="https://unpkg.com/vanilla-datatables@latest/dist/vanilla-dataTables.min.js" type="text/javascript"></script>
我試圖通過在cshtml索引頁中調(diào)用下面的代碼來初始化索引頁中的表
<script>
var table = new DataTable("table");
</script>
Also tried
<script>
var table = new DataTable("#datatable");
</script>
其中table是我的表類名,datatable是表的id。但是什么也沒有出現(xiàn)。如果您需要任何其他詳細信息,請告訴我。一、 我正在使用。net內(nèi)核和MVC架構(gòu)中的bootstrap。
Edit
根據(jù)提供的答案,我最終使用同一Github repo中提到的簡單數(shù)據(jù)表作為解決方案,這是vanilla數(shù)據(jù)表的最新迭代:
https://github.com/fiduswriter/Simple-DataTables
并使用cshtml頁面底部的以下腳本進行初始化:
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@latest"></script>
<script>
// Simple Datatable
var mytable = document.querySelector('#datatable');
var dataTable = new simpleDatatables.DataTable(mytable,{
//Enter any additional config details required here if required. Else Leave Blank
});
</script>
您鏈接到的
Vanilla-DataTables
repo有幾個使用腳本的示例鏈接。DataTable
中使用的值。ctor似乎是要綁定Vanilla-DataTables
的HTML表的類名。因此,在您的示例中,如果您使用:
然后您需要有一個HTML
table
和一個名為table
的css類:來源:Vanilla-DataTable演示>默認設置