I am using jquery.dataTables.js and I'm trying to drag and drop rows from one table to another and vice-versa from table 2 to table1 like this sample: http://jsfiddle.net/yf47u/
Above sample was with json so I would like to make the same work with my json sample.
this is my 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);
});
});
Here is my solution to this problem based on your code. It's possible to drag and drop rows from one table to the other one, but I was compelled to change values of the FirstName column dynamically, because otherwise a table would consider two rows with an identical FirstName equal, which would be a problem when removing one of those identical rows. Generally, tables should have a unique key in such cases.
JavaScript:
JSFiddle: http://jsfiddle.net/jahn08/f7debwj2/34/