2
jquery & datatableリファレンスがページに追加されていますが、開発ツールが開かれると、Jquery.Datatableを使用してテーブルを生成しようとしています。ここでは順番に、 ので、任意の助けjquery mvcプロジェクトでdatatableが動作しない
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/jquery.dataTables.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Content/jquery.dataTables.js"></script>
<table id="datatableId" data-url="@Url.Action("Index","Home")" cellspacing="0" width="100%" class="table table-responsive table-bordered table-striped">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Data</th>
<th>Actions</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script>
var datatable = {
table: null,
initializedDataTable: function() {
var $tablea = $(".table-striped");
datatable.table = $tablea.DataTable({
processing: true,
serverSide: true,
"alengthMenu": [[10, 20, 30, 40, 50], [10, 20, 30, 40, 50]],
ajax: {
url: $tablea.prop("data-url"),
type: "POST"
},
"columns": [{ "data": "FirstName" },
{ "data": "LasttName" },
{ "data": "Gender" }],
"columnDefs": [
{
"render": function (data, type, row) {
var inner = '<div class="btn-group">' +
'<button type="button" class="btn btn-secondary dropdwon-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' +
'Actions' +
'</button>' +
'<div class="dropdown-menu">' +
'<a href="#" class="drop-down-item btn btn-default edit" data-id="' + row.id + '" >Edit</a>' +
'<a href="#" class="drop-down-item btn btn-default delete" data-id="' + row.id + '" >delete</a>' +
'</div>' +
'</div>';
return inner;
},
"targets": -1
}
],
"pagingType": "full_numbers"
});
datatable.table.on('draw', function() {
$('button[data-type="delete"]').click(function() {
var $button = $(this);
});
$('button[data-type="Edit"').click(function() {
});
});
},
getData: function() {
if (datatable.table == null) {
datatable.initializedDataTable();
} else {
datatable.table.ajax.reload();
}
}
}
$(document).ready(function() {
datatable.getData();
});
</script>
はあなたが がキャッチされない例外TypeError、uはコンソール –
確かになったエラーを投稿返事をありがとうください可能性:Object.initializedDataTableで$ tablea.DataTableが機能 ではありません(インデックス:78) Object.getData(Index:126) at HTMLDocument(インデックス:136)火災で (jqueryの-1.10.2.js:3062)[resolveWithとして] Object.fireWith(jQueryの-1.10.2.js:3174)で 関数で 。準備完了(jquery-1.10.2.js:447) HTMLDocument.completed(jquery-1.10.2.js:118) –
DataTable jの404エラーが表示されていないことをコンソールでチェックするか、またはクリックしてください新しいタブで開くためのデータテーブルスクリプト。ファイル参照に問題があるようです。 –