Я работаю над сопоставлением функций между двумя таблицами и не могу выполнить перетаскивание одной строки таблицы в строку другой таблицы.
Прежде всего, я хочу знать, возможно ли ее использованиетаблицы?
Я разрабатываю в угловых 1,5
Фрагмент кода:
<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;
};
Проблема: Когда я начинаю перетаскивать tr из первой таблицы, вызывается только событие dragstart, и больше ничего не происходит.Буду признателен за любую помощь.
Редактировать:
Код директивы:
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();
};
}
});