1
jquery.dataTables.jsを使用していますが、このサンプルのようにテーブル2からテーブル1に行をドラッグしたりドロップしたりしようとしています:http://jsfiddle.net/yf47u/Jqueryデータテーブル1つのテーブルから別のテーブルに行をドラッグアンドドロップする
上記のサンプルはjsonと同じだったので、私はjsonサンプルで同じ作業をしたいと思います。
これは私のjsfiddleです:http://jsfiddle.net/f7debwj2/12/
HTML:
<br>
<br>
<h1>
table1
</h1><br>
<br>
<table id="example" class="display" width="100%" cellspacing="0">
<thead>
<tr>
<th>First name</th>
<th>Place</th>
<th>Order</th>
</tr>
</thead>
</table>
<br>
<br>
<h1>
table 2
</h1><br>
<br>
<table id="example2" class="display" width="100%" cellspacing="0">
<thead>
<tr>
<th>First name</th>
<th>Place</th>
<th>checkbox</th>
</tr>
</thead>
</table>
jqueryの:
$(document).ready(function() {
var dt = $('#example').dataTable();
dt.fnDestroy();
});
$(document).ready(function() {
var url = 'http://www.json-generator.com/api/json/get/clmDuyndua?indent=2';
var table = $('#example').DataTable({
ajax: url,
createdRow: function(row, data, dataIndex) {
$(row).attr('id', 'row-' + dataIndex);
},
rowReorder: {
dataSrc: 'order',
},
columns: [{
data: 'order'
}, {
data: 'name'
}, {
data: 'place'
}]
});
table.rowReordering();
});
$(document).ready(function() {
var dt = $('#example2').dataTable();
dt.fnDestroy();
});
$(document).ready(function() {
var url = 'http://www.json-generator.com/api/json/get/cnmZgfsBKa?indent=2';
var table = $('#example2').DataTable({
ajax: url,
createdRow: function(row, data, dataIndex) {
$(row).attr('id', 'row-' + dataIndex);
},
rowReorder: {
dataSrc: 'order',
},
columns: [{
data: 'order'
}, {
data: 'name'
}, {
data: 'checkbox'
}]
});
table.rowReordering();
});
$(document).ready(function() {
$('body').on('mouseenter', 'input', function() {
$('.btn').prop('disabled', true);
});
$('body').on('mouseout', 'input', function() {
$('.btn').prop('disabled', false);
});
});
はあなたにこのヘルプのために多くの人に感謝し、わずか2多くの質問私は表2に表1からドラッグドロップをブロックすることができますか?行全体を移動する代わりに、単に列を移動することもできますか?そして置き換える?サンプル:テーブル2の列の場所をドラッグしてテーブル1の場所にドラッグしますか?そのフィールドを新しいデータで更新しますか?列全体を動かすのではなく、どうもありがとう。 – Raduken
ようこそ。 2番目の質問はより精巧で、例を変更するには時間が必要です。あなたの目標を考えると、ほぼ同じロジックを適用する必要がありますが、行の代わりにセルプロパティに適用されます。ブロッキングについては、確実にドラッグアンドドロップをブロックすることは可能です。マウスイベントを最初のテーブルから削除するだけで済みます。このようなもの:http://jsfiddle.net/jahn08/f7debwj2/35/ –
ok npありがとう、私はプラグインを変更し、私はdatatablesから公式のものを使用しているので、あなたのコードをそのjsfiddleで動作させることは可能です? :http://jsfiddle.net/f7debwj2/37/ありがとうございます – Raduken