\r\n```\r\n\r\n> datatablesバージョン \r\nFile: jquery.dataTables.min.js\r\n Version: 1.9.2\r\n\r\ntableは、[charisma](https://usman.it/themes/charisma/table.html)のテーブルテンプレートを使用しています。\r\n不足情報等ございましたら、ご指摘下さいませ。\r\n何卒 宜しくお願い致します。","answerCount":2,"upvoteCount":0,"datePublished":"2018-02-14T13:28:34.501Z","dateModified":"2022-01-12T10:55:45.698Z","suggestedAnswer":[{"@type":"Answer","text":"Cannot reinitialise DataTable\r\n\r\nデータテーブルを再初期化できません。\r\nてことだから 同じテーブルですでにデータテーブルを構築してるだけでしょ\r\n\r\n## 追記\r\n`$(\"#selector\").DataTable({ destroy : true });` → 1.9 系では未実装\r\n`$(\"#selector\").DataTable({ retrieve: true });` → 1.9 系では未実装\r\n\r\n[github.com - jquery.dataTables.1.9.2.js](https://github.com/DataTables/DataTables/blob/RELEASE_1_9_2/media/js/jquery.dataTables.js)","dateModified":"2018-02-15T01:48:22.126Z","datePublished":"2018-02-14T14:25:22.800Z","upvoteCount":3,"url":"https://teratail.com/questions/113524#reply-172810","comment":[{"@type":"Comment","text":"確かにエラーメッセージを見るとそうですね。","datePublished":"2018-02-14T14:49:14.462Z","dateModified":"2018-02-14T14:49:14.462Z"},{"@type":"Comment","text":"https://jsfiddle.net/qtdcuua4/2/\r\n\r\n提示されてる場所だけ設定すれば正常動作ですから","datePublished":"2018-02-14T14:59:53.948Z","dateModified":"2018-02-14T14:59:53.948Z"},{"@type":"Comment","text":"おお、検証しているとは。さすがです!","datePublished":"2018-02-14T15:03:07.416Z","dateModified":"2018-02-14T15:03:07.416Z"},{"@type":"Comment","text":"調べた結果、そのことはわかっていますが、\r\ndestroy: trueや、retrieve: trueも効果がありませんでした。","datePublished":"2018-02-14T15:22:49.327Z","dateModified":"2018-02-14T15:22:49.327Z"},{"@type":"Comment","text":"そのことが分かっているとはどういうことでしょう?","datePublished":"2018-02-14T15:26:59.579Z","dateModified":"2018-02-14T15:26:59.579Z"},{"@type":"Comment","text":"提示された範囲だけでは問題ないので誰も回答はできないです。\r\n\r\n再構築時は以下のような処理になります。\r\n\r\n$table = $(\"#result-table\").DataTable();\r\n$table .destroy(); // 再構築するまえに除去する\r\n$table = $(\"#result-table\").DataTable();","datePublished":"2018-02-14T15:35:10.014Z","dateModified":"2018-02-14T15:35:10.014Z"},{"@type":"Comment","text":"ちなみに同じメッセージを出すように改変\r\n\r\nhttps://jsfiddle.net/asahina/qtdcuua4/4/","datePublished":"2018-02-14T15:38:33.048Z","dateModified":"2018-02-14T15:38:33.048Z"},{"@type":"Comment","text":"マニュアル通り再構築をする\r\n\r\nhttps://jsfiddle.net/asahina/qtdcuua4/6/","datePublished":"2018-02-14T15:39:44.333Z","dateModified":"2018-02-14T15:39:44.333Z"},{"@type":"Comment","text":"destroy: true オプション\r\n\r\nhttps://jsfiddle.net/asahina/qtdcuua4/9/","datePublished":"2018-02-14T15:41:59.536Z","dateModified":"2018-02-14T15:41:59.536Z"},{"@type":"Comment","text":"珍しくasahina1979さんが激レスしてるw\r\n質問する側は回答者に分かるようにネタをすべてださないと回答は難しいですよ","datePublished":"2018-02-14T15:43:06.862Z","dateModified":"2018-02-14T15:43:06.862Z"},{"@type":"Comment","text":"retrieve: true\r\n\r\nhttps://jsfiddle.net/asahina/qtdcuua4/12/","datePublished":"2018-02-14T15:43:39.052Z","dateModified":"2018-02-14T15:43:39.052Z"},{"@type":"Comment","text":"てことで質問者のそのページのJSのソースを全部ださんとエスパー以外わからん","datePublished":"2018-02-14T15:45:12.980Z","dateModified":"2018-02-14T15:45:12.980Z"},{"@type":"Comment","text":"asahina様\r\nご丁寧に有難うございます。\r\nやはり、エラーは消えません。","datePublished":"2018-02-14T15:45:40.351Z","dateModified":"2018-02-14T15:45:40.351Z"},{"@type":"Comment","text":"んー、抽象的な意見はどうでもいいから明確にどうしたのかとか現状のjsとかを貼ってくれとasahina1979さんも言ってるんですけどね。ここまで検証してくれる回答者は稀有ですよ。","datePublished":"2018-02-14T15:48:12.289Z","dateModified":"2018-02-14T15:48:12.289Z"},{"@type":"Comment","text":"追記していますが、その他に不足情報はございますでしょうか。","datePublished":"2018-02-14T15:50:17.705Z","dateModified":"2018-02-14T15:50:17.705Z"},{"@type":"Comment","text":"んーと、貼ったのは全量ですかね?","datePublished":"2018-02-14T16:15:34.601Z","dateModified":"2018-02-14T16:15:34.601Z"},{"@type":"Comment","text":"htmlも\r\nも含めて全て貼るべきではと思います。","datePublished":"2018-02-15T00:46:57.409Z","dateModified":"2018-02-15T00:46:57.409Z"},{"@type":"Comment","text":"ソースコードが10000文字を超えているため、全文を貼ることができません。\r\n申し訳有りません。","datePublished":"2018-02-15T01:17:29.246Z","dateModified":"2018-02-15T01:21:45.716Z"},{"@type":"Comment","text":"GitHubとかフリーなストレージとかに置いて共有するとかできないですかね?","datePublished":"2018-02-15T01:35:07.741Z","dateModified":"2018-02-15T01:35:25.406Z"},{"@type":"Comment","text":"5年以上前の遺物の 1.9.2 か・・・ 情報が出てこない気がするな\r\n1.10 で大幅に更新されているから 技術情報に互換性がないんだよね。。。","datePublished":"2018-02-15T02:11:20.307Z","dateModified":"2018-02-15T02:11:20.307Z"},{"@type":"Comment","text":"バージョンが低かったのですね。\r\ncharismaのテンプレートは使わずに公式から拾って、作り直してみます。\r\nご丁寧にお調べ頂きまして、有難うございました。","datePublished":"2018-02-15T02:43:06.356Z","dateModified":"2018-02-15T02:43:06.356Z"}]},{"@type":"Answer","text":"[参考URL](https://datatables.net/reference/option/lengthMenu)\r\n```\r\n$(\"#result-table\").dataTable({\r\n \"lengthMenu\": [ 10, 20, 30, 40, 50 ],\r\n```\r\nみたいに記述してもだめですか?","dateModified":"2018-02-14T14:08:19.731Z","datePublished":"2018-02-14T14:08:19.731Z","upvoteCount":0,"url":"https://teratail.com/questions/113524#reply-172806","comment":[{"@type":"Comment","text":"ご回答有難うございます。\r\n同じエラーが出ます。","datePublished":"2018-02-14T15:19:03.695Z","dateModified":"2018-02-14T15:19:03.695Z"},{"@type":"Comment","text":"asahina1979さんの回答を見てくださいね","datePublished":"2018-02-14T15:22:37.422Z","dateModified":"2018-02-14T15:22:37.422Z"}]}],"breadcrumb":{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"https://teratail.com","name":"トップ"}},{"@type":"ListItem","position":2,"item":{"@id":"https://teratail.com/tags/HTML5","name":"HTML5に関する質問"}},{"@type":"ListItem","position":3,"item":{"@id":"https://teratail.com/questions/113524","name":"(jQuery)datatablesの表示件数を変更できない"}}]}}}
お世話になります。
jQueryのdatatablesのLengthMenuを変更出来ません。
エラーが発生してしまいます。
エラー内容:
DataTables warning: table id={id} - Cannot reinitialise DataTable.
エラー文言で何度も調べましたが、解決することができませんでした。
アドバイスを頂けると幸いです。
該当ソースコードを記載いたします。
<div class="row">
<div class="box col-md-12">
<div class="box-inner">
<div class="box-header well" data-original-title="">
<h2><i class="glyphicon glyphicon-list"></i> 検索結果</h2>
<div class="box-icon">
<a href="#" class="btn btn-minimize btn-round btn-default"><i class="glyphicon glyphicon-chevron-up"></i></a>
<a href="#" class="btn btn-close btn-round btn-default"><i class="glyphicon glyphicon-remove"></i></a>
</div>
</div>
<div class="box-content result">
<table class="table table-striped table-bordered bootstrap-datatable datatable responsive" id="result-table">
<thead>
<tr>
<th>Username</th>
<th>Date registered</th>
<th>Role</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td>David R</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label-success label label-default">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="glyphicon glyphicon-zoom-in icon-white"></i>View
</a>
<a class="btn btn-info" href="#">
<i class="glyphicon glyphicon-edit icon-white"></i>Edit
</a>
<a class="btn btn-danger" href="#">
<i class="glyphicon glyphicon-trash icon-white"></i>Delete
</a>
</td>
</tr>
<tr>
<td>Chris Jack</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label-success label label-default">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="glyphicon glyphicon-zoom-in icon-white"></i>View
</a>
<a class="btn btn-info" href="#">
<i class="glyphicon glyphicon-edit icon-white"></i>Edit
</a>
<a class="btn btn-danger" href="#">
<i class="glyphicon glyphicon-trash icon-white"></i>Delete
</a>
</td>
</tr>
<tr>
<td>Jack Chris</td>
<td class="center">2012/01/01</td>
<td class="center">Member</td>
<td class="center">
<span class="label-success label label-default">Active</span>
</td>
<td class="center">
<a class="btn btn-success" href="#">
<i class="glyphicon glyphicon-zoom-in icon-white"></i>View
</a>
<a class="btn btn-info" href="#">
<i class="glyphicon glyphicon-edit icon-white"></i>Edit
</a>
<a class="btn btn-danger" href="#">
<i class="glyphicon glyphicon-trash icon-white"></i>Delete
</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
$("#result-table").DataTable({
// 件数切替の値を10~50の10刻みにする
lengthMenu: [ 10, 20, 30, 40, 50 ],
// 件数のデフォルトの値を50にする
displayLength: 50,
scrollX: true,
scrollY: 200,
columnDefs: [
{ targets: 0, visible: false },
{ targets: 1, width: 100 }
]
});
<script>
$(function() {
$("#datePiceker_begin").datepicker();
});
$(function() {
$("#datePiceker_end").datepicker();
});
$('#clear').click(function() {
$('.form-control').val("");
});
$('#search_condition').click(function() {
if ($('#search_condition_list').is(':visible')) {
$('#search_condition_list').animate({
height: 'hide'
}, "normal");
$('#search_condition').text("▶︎Search Condition");
} else {
$('#search_condition_list').animate({
height: 'show'
}, "normal");
$('#search_condition').text("▼Search Condition");
}
});
table = $("#result-table").DataTable();
table.destroy();
table = $("#result-table").DataTable({
// 件数切替の値を10~50の10刻みにする
lengthMenu: [ 10, 20, 30, 40, 50 ],
// 件数のデフォルトの値を50にする
displayLength: 50,
scrollX: true,
scrollY: 200,
columnDefs: [
{ targets: 0, visible: false },
{ targets: 1, width: 100 }
]
});
</script>
datatablesバージョン
File: jquery.dataTables.min.js
Version: 1.9.2
tableは、charismaのテーブルテンプレートを使用しています。
不足情報等ございましたら、ご指摘下さいませ。
何卒 宜しくお願い致します。
Cannot reinitialise DataTable
データテーブルを再初期化できません。
てことだから 同じテーブルですでにデータテーブルを構築してるだけでしょ
追記
$("#selector").DataTable({ destroy : true }); → 1.9 系では未実装
$("#selector").DataTable({ retrieve: true }); → 1.9 系では未実装
github.com - jquery.dataTables.1.9.2.js
参考URL
$("#result-table").dataTable({
"lengthMenu": [ 10, 20, 30, 40, 50 ],
みたいに記述してもだめですか?
15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.29%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる
質問する