Drag and drop a tr of table 1 on to a tr of table 2












0















I am working on a matching functionality between two tables and unable to achieve the drag and drop of one table row on to the other table's row.



First of all, I want to know if its possible using tables?



I am developing in angular 1.5



Code snippet:



<table class="table table-hover header-fixed">
<thead>
<th>Part Num</th>
<th>Line Abbrev</th>
<th>Desc</th>
<th>Qty</th>
<th></th>
</thead>
<tbody>
<tr ng-if="$ctrl.ppseList.length > 0"
ng-repeat="p in $ctrl.ppseList"
ng-class="{'active': ($index == $ctrl.pair.secondary)}"
ng-click="click($index, false)"
draggable="true"
ng-dragstart="onDragStart($event, $index)"
ng-dragend="onDragEnd($event)">
<td>{{p.PartNum}}</td>
<td>{{p.LineAbbrev}}</td>
<td>{{p.Desc}}</td>
<td>{{p.ReqQty}}</td>
<td>
<button type="button" name="button"
class="btn btn-xs btn-success"
ng-click="addCartItemToUncategorizedList(p, $index);"><i class="fa fa-plus"></i></button>
<button type="button" name="button"
class="btn btn-xs btn-danger"
ng-click="removeCartItemFromCart(p, $index);"><i class="fa fa-minus"></i></button>
</td>
</tr>
<tr ng-if="$ctrl.ppseList.length == 0">
<td>Cart is empty <i class="fa fa-star-half-empty"></i></td>
</tr>
</tbody>
</table>
<table class="table table-hover header-fixed"
>
<thead>
<th>Part Num</th>
<th>Line Abbrev</th>
<th>Desc</th>
<th>Qty</th>
</thead>
<tbody>
<tr ng-if="$ctrl.uncategorizedList.length > 0"
ng-repeat="p in $ctrl.uncategorizedList"
ng-class="{'active': ($index == $ctrl.pair.primary)}"
ng-click="click($index, true)" ng-dragover="onDragOver($event)"
ng-dragend="onDragEnd($event)">
<td>{{p.Partnum}}</td>
<td>{{p.LineAbbrv}}</td>
<td>{{p.Desc}}</td>
<td>{{p.ReqQty}}</td>
</tr>
<tr ng-if="$ctrl.uncategorizedList.length == 0">
<td colspan="4">No parts to match.</td>
</tr>
</tbody>
</table>


Javascript:



$scope.onDragStart = function (e, index) {
console.log('Started', e);
e.target.style.opacity = '0.4';
};



$scope.onDragEnd = function (e) {
console.log('End', e);
};



$scope.onDrop = function (e) {
console.log('Drop', e.dataTransfer.getData('Text'));
};

$scope.onDragOver = function (e) {
console.log('Drag Over', e);
if (e.preventDefault) {
e.preventDefault(); // Necessary. Allows us to drop.
}

e.dataTransfer.dropEffect = 'move'; // See the section on the DataTransfer object.

return false;
};


Problem:
When I start dragging the tr from the first table, only dragstart event is being called and nothing else is happening.
Any help would be appreciated.



Edit:



Directive code:



App.directive('ngDragenter', function($parse) {


return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragenter);
element[0].ondragenter = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragenter);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragleave', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragleave);
element[0].ondragleave = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragleave);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragstart', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragstart);
element[0].ondragstart = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragleave);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragend', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragend);
element[0].ondragend = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragend);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragover', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragover);
element[0].ondragover = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragend);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDrop', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDrop);
element[0].ondrop = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragend);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
});









share|improve this question




















  • 2





    please share code what you have tried so far

    – Naga Sai A
    Dec 28 '18 at 16:27











  • Added the code @NagaSaiA

    – pradyumnad
    Dec 28 '18 at 17:03
















0















I am working on a matching functionality between two tables and unable to achieve the drag and drop of one table row on to the other table's row.



First of all, I want to know if its possible using tables?



I am developing in angular 1.5



Code snippet:



<table class="table table-hover header-fixed">
<thead>
<th>Part Num</th>
<th>Line Abbrev</th>
<th>Desc</th>
<th>Qty</th>
<th></th>
</thead>
<tbody>
<tr ng-if="$ctrl.ppseList.length > 0"
ng-repeat="p in $ctrl.ppseList"
ng-class="{'active': ($index == $ctrl.pair.secondary)}"
ng-click="click($index, false)"
draggable="true"
ng-dragstart="onDragStart($event, $index)"
ng-dragend="onDragEnd($event)">
<td>{{p.PartNum}}</td>
<td>{{p.LineAbbrev}}</td>
<td>{{p.Desc}}</td>
<td>{{p.ReqQty}}</td>
<td>
<button type="button" name="button"
class="btn btn-xs btn-success"
ng-click="addCartItemToUncategorizedList(p, $index);"><i class="fa fa-plus"></i></button>
<button type="button" name="button"
class="btn btn-xs btn-danger"
ng-click="removeCartItemFromCart(p, $index);"><i class="fa fa-minus"></i></button>
</td>
</tr>
<tr ng-if="$ctrl.ppseList.length == 0">
<td>Cart is empty <i class="fa fa-star-half-empty"></i></td>
</tr>
</tbody>
</table>
<table class="table table-hover header-fixed"
>
<thead>
<th>Part Num</th>
<th>Line Abbrev</th>
<th>Desc</th>
<th>Qty</th>
</thead>
<tbody>
<tr ng-if="$ctrl.uncategorizedList.length > 0"
ng-repeat="p in $ctrl.uncategorizedList"
ng-class="{'active': ($index == $ctrl.pair.primary)}"
ng-click="click($index, true)" ng-dragover="onDragOver($event)"
ng-dragend="onDragEnd($event)">
<td>{{p.Partnum}}</td>
<td>{{p.LineAbbrv}}</td>
<td>{{p.Desc}}</td>
<td>{{p.ReqQty}}</td>
</tr>
<tr ng-if="$ctrl.uncategorizedList.length == 0">
<td colspan="4">No parts to match.</td>
</tr>
</tbody>
</table>


Javascript:



$scope.onDragStart = function (e, index) {
console.log('Started', e);
e.target.style.opacity = '0.4';
};



$scope.onDragEnd = function (e) {
console.log('End', e);
};



$scope.onDrop = function (e) {
console.log('Drop', e.dataTransfer.getData('Text'));
};

$scope.onDragOver = function (e) {
console.log('Drag Over', e);
if (e.preventDefault) {
e.preventDefault(); // Necessary. Allows us to drop.
}

e.dataTransfer.dropEffect = 'move'; // See the section on the DataTransfer object.

return false;
};


Problem:
When I start dragging the tr from the first table, only dragstart event is being called and nothing else is happening.
Any help would be appreciated.



Edit:



Directive code:



App.directive('ngDragenter', function($parse) {


return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragenter);
element[0].ondragenter = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragenter);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragleave', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragleave);
element[0].ondragleave = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragleave);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragstart', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragstart);
element[0].ondragstart = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragleave);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragend', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragend);
element[0].ondragend = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragend);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragover', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragover);
element[0].ondragover = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragend);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDrop', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDrop);
element[0].ondrop = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragend);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
});









share|improve this question




















  • 2





    please share code what you have tried so far

    – Naga Sai A
    Dec 28 '18 at 16:27











  • Added the code @NagaSaiA

    – pradyumnad
    Dec 28 '18 at 17:03














0












0








0








I am working on a matching functionality between two tables and unable to achieve the drag and drop of one table row on to the other table's row.



First of all, I want to know if its possible using tables?



I am developing in angular 1.5



Code snippet:



<table class="table table-hover header-fixed">
<thead>
<th>Part Num</th>
<th>Line Abbrev</th>
<th>Desc</th>
<th>Qty</th>
<th></th>
</thead>
<tbody>
<tr ng-if="$ctrl.ppseList.length > 0"
ng-repeat="p in $ctrl.ppseList"
ng-class="{'active': ($index == $ctrl.pair.secondary)}"
ng-click="click($index, false)"
draggable="true"
ng-dragstart="onDragStart($event, $index)"
ng-dragend="onDragEnd($event)">
<td>{{p.PartNum}}</td>
<td>{{p.LineAbbrev}}</td>
<td>{{p.Desc}}</td>
<td>{{p.ReqQty}}</td>
<td>
<button type="button" name="button"
class="btn btn-xs btn-success"
ng-click="addCartItemToUncategorizedList(p, $index);"><i class="fa fa-plus"></i></button>
<button type="button" name="button"
class="btn btn-xs btn-danger"
ng-click="removeCartItemFromCart(p, $index);"><i class="fa fa-minus"></i></button>
</td>
</tr>
<tr ng-if="$ctrl.ppseList.length == 0">
<td>Cart is empty <i class="fa fa-star-half-empty"></i></td>
</tr>
</tbody>
</table>
<table class="table table-hover header-fixed"
>
<thead>
<th>Part Num</th>
<th>Line Abbrev</th>
<th>Desc</th>
<th>Qty</th>
</thead>
<tbody>
<tr ng-if="$ctrl.uncategorizedList.length > 0"
ng-repeat="p in $ctrl.uncategorizedList"
ng-class="{'active': ($index == $ctrl.pair.primary)}"
ng-click="click($index, true)" ng-dragover="onDragOver($event)"
ng-dragend="onDragEnd($event)">
<td>{{p.Partnum}}</td>
<td>{{p.LineAbbrv}}</td>
<td>{{p.Desc}}</td>
<td>{{p.ReqQty}}</td>
</tr>
<tr ng-if="$ctrl.uncategorizedList.length == 0">
<td colspan="4">No parts to match.</td>
</tr>
</tbody>
</table>


Javascript:



$scope.onDragStart = function (e, index) {
console.log('Started', e);
e.target.style.opacity = '0.4';
};



$scope.onDragEnd = function (e) {
console.log('End', e);
};



$scope.onDrop = function (e) {
console.log('Drop', e.dataTransfer.getData('Text'));
};

$scope.onDragOver = function (e) {
console.log('Drag Over', e);
if (e.preventDefault) {
e.preventDefault(); // Necessary. Allows us to drop.
}

e.dataTransfer.dropEffect = 'move'; // See the section on the DataTransfer object.

return false;
};


Problem:
When I start dragging the tr from the first table, only dragstart event is being called and nothing else is happening.
Any help would be appreciated.



Edit:



Directive code:



App.directive('ngDragenter', function($parse) {


return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragenter);
element[0].ondragenter = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragenter);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragleave', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragleave);
element[0].ondragleave = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragleave);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragstart', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragstart);
element[0].ondragstart = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragleave);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragend', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragend);
element[0].ondragend = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragend);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragover', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragover);
element[0].ondragover = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragend);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDrop', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDrop);
element[0].ondrop = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragend);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
});









share|improve this question
















I am working on a matching functionality between two tables and unable to achieve the drag and drop of one table row on to the other table's row.



First of all, I want to know if its possible using tables?



I am developing in angular 1.5



Code snippet:



<table class="table table-hover header-fixed">
<thead>
<th>Part Num</th>
<th>Line Abbrev</th>
<th>Desc</th>
<th>Qty</th>
<th></th>
</thead>
<tbody>
<tr ng-if="$ctrl.ppseList.length > 0"
ng-repeat="p in $ctrl.ppseList"
ng-class="{'active': ($index == $ctrl.pair.secondary)}"
ng-click="click($index, false)"
draggable="true"
ng-dragstart="onDragStart($event, $index)"
ng-dragend="onDragEnd($event)">
<td>{{p.PartNum}}</td>
<td>{{p.LineAbbrev}}</td>
<td>{{p.Desc}}</td>
<td>{{p.ReqQty}}</td>
<td>
<button type="button" name="button"
class="btn btn-xs btn-success"
ng-click="addCartItemToUncategorizedList(p, $index);"><i class="fa fa-plus"></i></button>
<button type="button" name="button"
class="btn btn-xs btn-danger"
ng-click="removeCartItemFromCart(p, $index);"><i class="fa fa-minus"></i></button>
</td>
</tr>
<tr ng-if="$ctrl.ppseList.length == 0">
<td>Cart is empty <i class="fa fa-star-half-empty"></i></td>
</tr>
</tbody>
</table>
<table class="table table-hover header-fixed"
>
<thead>
<th>Part Num</th>
<th>Line Abbrev</th>
<th>Desc</th>
<th>Qty</th>
</thead>
<tbody>
<tr ng-if="$ctrl.uncategorizedList.length > 0"
ng-repeat="p in $ctrl.uncategorizedList"
ng-class="{'active': ($index == $ctrl.pair.primary)}"
ng-click="click($index, true)" ng-dragover="onDragOver($event)"
ng-dragend="onDragEnd($event)">
<td>{{p.Partnum}}</td>
<td>{{p.LineAbbrv}}</td>
<td>{{p.Desc}}</td>
<td>{{p.ReqQty}}</td>
</tr>
<tr ng-if="$ctrl.uncategorizedList.length == 0">
<td colspan="4">No parts to match.</td>
</tr>
</tbody>
</table>


Javascript:



$scope.onDragStart = function (e, index) {
console.log('Started', e);
e.target.style.opacity = '0.4';
};



$scope.onDragEnd = function (e) {
console.log('End', e);
};



$scope.onDrop = function (e) {
console.log('Drop', e.dataTransfer.getData('Text'));
};

$scope.onDragOver = function (e) {
console.log('Drag Over', e);
if (e.preventDefault) {
e.preventDefault(); // Necessary. Allows us to drop.
}

e.dataTransfer.dropEffect = 'move'; // See the section on the DataTransfer object.

return false;
};


Problem:
When I start dragging the tr from the first table, only dragstart event is being called and nothing else is happening.
Any help would be appreciated.



Edit:



Directive code:



App.directive('ngDragenter', function($parse) {


return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragenter);
element[0].ondragenter = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragenter);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragleave', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragleave);
element[0].ondragleave = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragleave);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragstart', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragstart);
element[0].ondragstart = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragleave);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragend', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragend);
element[0].ondragend = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragend);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDragover', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDragover);
element[0].ondragover = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragend);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
})
.directive('ngDrop', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.ngDrop);
element[0].ondrop = function(e) {
scope.$apply(function() {
// scope.$eval(attrs.ngDragend);
fn(scope, {
$event: event
});
});
e.stopPropagation();
e.preventDefault();
};
}
});






javascript html angularjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 16:01







pradyumnad

















asked Dec 28 '18 at 16:27









pradyumnadpradyumnad

380316




380316








  • 2





    please share code what you have tried so far

    – Naga Sai A
    Dec 28 '18 at 16:27











  • Added the code @NagaSaiA

    – pradyumnad
    Dec 28 '18 at 17:03














  • 2





    please share code what you have tried so far

    – Naga Sai A
    Dec 28 '18 at 16:27











  • Added the code @NagaSaiA

    – pradyumnad
    Dec 28 '18 at 17:03








2




2





please share code what you have tried so far

– Naga Sai A
Dec 28 '18 at 16:27





please share code what you have tried so far

– Naga Sai A
Dec 28 '18 at 16:27













Added the code @NagaSaiA

– pradyumnad
Dec 28 '18 at 17:03





Added the code @NagaSaiA

– pradyumnad
Dec 28 '18 at 17:03












1 Answer
1






active

oldest

votes


















0














To achieve expected result, use below option of HTML5 drag and drop




  1. Use index and set row id for first table

  2. Use draggable true to allow dragging for first table rows

  3. Using id of dragged element , append to second table


codepen- https://codepen.io/nagasai/pen/BvwWwd






var app = angular.module('myApp', );
app.controller('myCtrl', function($scope) {
$scope.tab1 = [{
id: 1,
name: "a"
},{
id: 2,
name: "b"
},{
id: 3,
name: "c"
}]

$scope.tab2 = [{
id: 1,
name: "aa"
},{
id: 2,
name: "bb"
},{
id: 3,
name: "cc"
}]
});

function allowDrop(ev) {
ev.preventDefault();
}

function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}

function drop(ev, el) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
el.appendChild(document.getElementById(data));
}

table tr td {
border: 1px solid black;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<div>Table 1
<table>
<tr ng-repeat="x in tab1" id="row{{$index}}" draggable="true"
ondragstart="drag(event)">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>
<div>Table 2
<table ondrop="drop(event, this)" ondragover="allowDrop(event)">
<tr ng-repeat="x in tab2">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>

</div>


</body>





Option 2: Using angular drag and drop library with list elements



http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple






share|improve this answer
























  • The javascript code is working fine but when I make use of the directives, it isn't working. I've added the directive code above.

    – pradyumnad
    Jan 2 at 15:59













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53961470%2fdrag-and-drop-a-tr-of-table-1-on-to-a-tr-of-table-2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














To achieve expected result, use below option of HTML5 drag and drop




  1. Use index and set row id for first table

  2. Use draggable true to allow dragging for first table rows

  3. Using id of dragged element , append to second table


codepen- https://codepen.io/nagasai/pen/BvwWwd






var app = angular.module('myApp', );
app.controller('myCtrl', function($scope) {
$scope.tab1 = [{
id: 1,
name: "a"
},{
id: 2,
name: "b"
},{
id: 3,
name: "c"
}]

$scope.tab2 = [{
id: 1,
name: "aa"
},{
id: 2,
name: "bb"
},{
id: 3,
name: "cc"
}]
});

function allowDrop(ev) {
ev.preventDefault();
}

function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}

function drop(ev, el) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
el.appendChild(document.getElementById(data));
}

table tr td {
border: 1px solid black;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<div>Table 1
<table>
<tr ng-repeat="x in tab1" id="row{{$index}}" draggable="true"
ondragstart="drag(event)">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>
<div>Table 2
<table ondrop="drop(event, this)" ondragover="allowDrop(event)">
<tr ng-repeat="x in tab2">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>

</div>


</body>





Option 2: Using angular drag and drop library with list elements



http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple






share|improve this answer
























  • The javascript code is working fine but when I make use of the directives, it isn't working. I've added the directive code above.

    – pradyumnad
    Jan 2 at 15:59


















0














To achieve expected result, use below option of HTML5 drag and drop




  1. Use index and set row id for first table

  2. Use draggable true to allow dragging for first table rows

  3. Using id of dragged element , append to second table


codepen- https://codepen.io/nagasai/pen/BvwWwd






var app = angular.module('myApp', );
app.controller('myCtrl', function($scope) {
$scope.tab1 = [{
id: 1,
name: "a"
},{
id: 2,
name: "b"
},{
id: 3,
name: "c"
}]

$scope.tab2 = [{
id: 1,
name: "aa"
},{
id: 2,
name: "bb"
},{
id: 3,
name: "cc"
}]
});

function allowDrop(ev) {
ev.preventDefault();
}

function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}

function drop(ev, el) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
el.appendChild(document.getElementById(data));
}

table tr td {
border: 1px solid black;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<div>Table 1
<table>
<tr ng-repeat="x in tab1" id="row{{$index}}" draggable="true"
ondragstart="drag(event)">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>
<div>Table 2
<table ondrop="drop(event, this)" ondragover="allowDrop(event)">
<tr ng-repeat="x in tab2">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>

</div>


</body>





Option 2: Using angular drag and drop library with list elements



http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple






share|improve this answer
























  • The javascript code is working fine but when I make use of the directives, it isn't working. I've added the directive code above.

    – pradyumnad
    Jan 2 at 15:59
















0












0








0







To achieve expected result, use below option of HTML5 drag and drop




  1. Use index and set row id for first table

  2. Use draggable true to allow dragging for first table rows

  3. Using id of dragged element , append to second table


codepen- https://codepen.io/nagasai/pen/BvwWwd






var app = angular.module('myApp', );
app.controller('myCtrl', function($scope) {
$scope.tab1 = [{
id: 1,
name: "a"
},{
id: 2,
name: "b"
},{
id: 3,
name: "c"
}]

$scope.tab2 = [{
id: 1,
name: "aa"
},{
id: 2,
name: "bb"
},{
id: 3,
name: "cc"
}]
});

function allowDrop(ev) {
ev.preventDefault();
}

function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}

function drop(ev, el) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
el.appendChild(document.getElementById(data));
}

table tr td {
border: 1px solid black;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<div>Table 1
<table>
<tr ng-repeat="x in tab1" id="row{{$index}}" draggable="true"
ondragstart="drag(event)">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>
<div>Table 2
<table ondrop="drop(event, this)" ondragover="allowDrop(event)">
<tr ng-repeat="x in tab2">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>

</div>


</body>





Option 2: Using angular drag and drop library with list elements



http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple






share|improve this answer













To achieve expected result, use below option of HTML5 drag and drop




  1. Use index and set row id for first table

  2. Use draggable true to allow dragging for first table rows

  3. Using id of dragged element , append to second table


codepen- https://codepen.io/nagasai/pen/BvwWwd






var app = angular.module('myApp', );
app.controller('myCtrl', function($scope) {
$scope.tab1 = [{
id: 1,
name: "a"
},{
id: 2,
name: "b"
},{
id: 3,
name: "c"
}]

$scope.tab2 = [{
id: 1,
name: "aa"
},{
id: 2,
name: "bb"
},{
id: 3,
name: "cc"
}]
});

function allowDrop(ev) {
ev.preventDefault();
}

function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}

function drop(ev, el) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
el.appendChild(document.getElementById(data));
}

table tr td {
border: 1px solid black;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<div>Table 1
<table>
<tr ng-repeat="x in tab1" id="row{{$index}}" draggable="true"
ondragstart="drag(event)">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>
<div>Table 2
<table ondrop="drop(event, this)" ondragover="allowDrop(event)">
<tr ng-repeat="x in tab2">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>

</div>


</body>





Option 2: Using angular drag and drop library with list elements



http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple






var app = angular.module('myApp', );
app.controller('myCtrl', function($scope) {
$scope.tab1 = [{
id: 1,
name: "a"
},{
id: 2,
name: "b"
},{
id: 3,
name: "c"
}]

$scope.tab2 = [{
id: 1,
name: "aa"
},{
id: 2,
name: "bb"
},{
id: 3,
name: "cc"
}]
});

function allowDrop(ev) {
ev.preventDefault();
}

function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}

function drop(ev, el) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
el.appendChild(document.getElementById(data));
}

table tr td {
border: 1px solid black;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<div>Table 1
<table>
<tr ng-repeat="x in tab1" id="row{{$index}}" draggable="true"
ondragstart="drag(event)">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>
<div>Table 2
<table ondrop="drop(event, this)" ondragover="allowDrop(event)">
<tr ng-repeat="x in tab2">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>

</div>


</body>





var app = angular.module('myApp', );
app.controller('myCtrl', function($scope) {
$scope.tab1 = [{
id: 1,
name: "a"
},{
id: 2,
name: "b"
},{
id: 3,
name: "c"
}]

$scope.tab2 = [{
id: 1,
name: "aa"
},{
id: 2,
name: "bb"
},{
id: 3,
name: "cc"
}]
});

function allowDrop(ev) {
ev.preventDefault();
}

function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}

function drop(ev, el) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
el.appendChild(document.getElementById(data));
}

table tr td {
border: 1px solid black;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<div>Table 1
<table>
<tr ng-repeat="x in tab1" id="row{{$index}}" draggable="true"
ondragstart="drag(event)">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>
<div>Table 2
<table ondrop="drop(event, this)" ondragover="allowDrop(event)">
<tr ng-repeat="x in tab2">
<td>{{x.id}}</td>
<td>{{x.name}}</td>
</tr>
</table>
</div>

</div>


</body>






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 28 '18 at 17:08









Naga Sai ANaga Sai A

5,5871825




5,5871825













  • The javascript code is working fine but when I make use of the directives, it isn't working. I've added the directive code above.

    – pradyumnad
    Jan 2 at 15:59





















  • The javascript code is working fine but when I make use of the directives, it isn't working. I've added the directive code above.

    – pradyumnad
    Jan 2 at 15:59



















The javascript code is working fine but when I make use of the directives, it isn't working. I've added the directive code above.

– pradyumnad
Jan 2 at 15:59







The javascript code is working fine but when I make use of the directives, it isn't working. I've added the directive code above.

– pradyumnad
Jan 2 at 15:59




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53961470%2fdrag-and-drop-a-tr-of-table-1-on-to-a-tr-of-table-2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas