I have two tabs(built using boostrap) and each tab has its own table.
I need to drag table row from one tab and drop into another tabs table. While dragging i want to open the tab under cursor before dropping into table. Any help appreciated.
This is my HTML code
<div class="tabbable" >
<ul class="nav nav-tabs" id="my-tabs">
<li class="active"><a href="#tab1" data-toggle="tab"> Tab1 </a></li>
<li class=""><a href="#tab2" data-toggle="tab"> Tab2 </a></li>
</ul>
</div>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<table id='table-draggable1'>
<thead>
<th>col1</th>
<th>col2</th>
<th>col3</th>
<th>col4</th>
</thead>
<tbody>
<tr>
<td>256</td>
<td>668</td>
<td>100.95</td>
<td>1.82</td>
</tr>
<tr>
<td>256</td>
<td>668</td>
<td>100.95</td>
<td>1.82</td>
</tr>
</tbody>
</table>
<div class="tab-pane" id="tab2">
<table id='table-draggable2'>
<thead>
<th>col1</th>
<th>col2</th>
<th>col3</th>
<th>col4</th>
</thead>
<tbody>
<tr>
<td>256</td>
<td>668</td>
<td>100.95</td>
<td>1.82</td>
</tr>
<tr>
<td>256</td>
<td>668</td>
<td>100.95</td>
<td>1.82</td>
</tr>
</tbody>
</table>
</div>
This is my JS code
$('.table-draggable1 tbody').draggable();
$('#my-tabs > li').droppable({
over:function(event, ui){
console.log(event.target);
},
drop:function(event,ui){
}
});
Here is a solution that combines jqueryUI droppable with sortable to satisfy your requirement:
$(document).ready(function() {
$tabs = $(".tabbable");
$('.nav-tabs a').click(function(e) {
e.preventDefault();
$(this).tab('show');
})
$( "tbody.connectedSortable" ).sortable({
connectWith: ".connectedSortable",
items: "> tr:not(:first)",
appendTo: $tabs,
helper:"clone",
zIndex: 99999,
start: function(){ $tabs.addClass("dragging") },
stop: function(){ $tabs.removeClass("dragging") }
});
var $tab_items = $( "ul:first > li", $tabs ).droppable({
accept: ".connectedSortable tr",
hoverClass: "ui-state-hover",
over: function( event, ui ) {
var $item = $( this );
$item.find("a").tab("show");
}
});
});
EDIT: Link to jsfiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With