angular-dragdrop
Implementing jQueryUI Drag and Drop functionality in AngularJS (with Animation) is easier than ever
Top Related Projects
jQuery UI Sortable for AngularJS
Angular directives for sorting nested lists using the HTML5 Drag & Drop API
:ok_hand: Drag and drop so simple it hurts
Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
Beautiful and accessible drag and drop for lists with React
Quick Overview
Angular-dragdrop is a drag and drop module for AngularJS applications. It provides a set of directives that allow developers to easily implement drag and drop functionality in their web applications, enhancing user interaction and interface design.
Pros
- Easy integration with AngularJS applications
- Supports both mouse and touch events for drag and drop
- Customizable with various options and callbacks
- Lightweight and performant
Cons
- Limited to AngularJS, not compatible with newer Angular versions (2+)
- May require additional styling for optimal visual feedback
- Documentation could be more comprehensive
- Not actively maintained (last update was in 2017)
Code Examples
- Basic drag and drop setup:
<ul>
<li ng-repeat="item in items" ui-draggable="true" drag="item">
{{item.name}}
</li>
</ul>
<div ui-on-drop="onDrop($data,$event)">
Drop zone
</div>
- Implementing drag start and drag stop callbacks:
<div ui-draggable="true"
drag="dragData"
on-drag-start="onDragStart($event)"
on-drag-end="onDragEnd($event)">
Drag me
</div>
- Using drag helper:
<div ui-draggable="true"
drag="dragData"
drag-channel="channel1"
helper="myHelper">
Drag with helper
</div>
Getting Started
- Install the module via npm:
npm install angular-dragdrop
- Include the module in your AngularJS app:
angular.module('myApp', ['ngDragDrop']);
- Use the directives in your HTML:
<div ng-controller="MyController">
<div ui-draggable="true" drag="itemData">Drag me</div>
<div ui-on-drop="onDrop($data,$event)">Drop here</div>
</div>
- Implement the controller logic:
angular.module('myApp').controller('MyController', function($scope) {
$scope.itemData = { name: 'Item 1' };
$scope.onDrop = function(data, event) {
console.log('Dropped:', data);
};
});
Competitor Comparisons
jQuery UI Sortable for AngularJS
Pros of ui-sortable
- Built on top of jQuery UI sortable, providing a more robust and feature-rich sorting experience
- Supports nested lists and complex sorting scenarios out of the box
- Integrates well with other Angular UI components
Cons of ui-sortable
- Requires jQuery and jQuery UI as dependencies, which may increase the overall bundle size
- Learning curve might be steeper due to the extensive options inherited from jQuery UI sortable
- May have performance issues with large lists or complex DOM structures
Code Comparison
angular-dragdrop:
<ul ng-model="list">
<li ng-repeat="item in list" drag="item" drop="onDrop($data, $event)">
{{item}}
</li>
</ul>
ui-sortable:
<ul ui-sortable ng-model="list">
<li ng-repeat="item in list">{{item}}</li>
</ul>
Summary
While angular-dragdrop provides a simpler API for basic drag and drop functionality, ui-sortable offers more advanced sorting capabilities at the cost of additional dependencies. The choice between the two depends on the specific requirements of your project, such as the complexity of sorting needed and the acceptable trade-offs in terms of bundle size and performance.
Angular directives for sorting nested lists using the HTML5 Drag & Drop API
Pros of angular-drag-and-drop-lists
- More actively maintained with recent updates
- Supports nested lists and complex drag-and-drop scenarios
- Better documentation and examples
Cons of angular-drag-and-drop-lists
- Slightly more complex setup for basic use cases
- May have a steeper learning curve for beginners
Code Comparison
angular-drag-and-drop-lists:
<ul dnd-list="list">
<li ng-repeat="item in list"
dnd-draggable="item"
dnd-moved="list.splice($index, 1)"
dnd-effect-allowed="move">
{{item.label}}
</li>
</ul>
angular-dragdrop:
<ul>
<li ng-repeat="item in list" ui-draggable="true" drag="item">
{{item.label}}
</li>
</ul>
<div ui-droppable="true" drop="handleDrop($data)"></div>
The angular-drag-and-drop-lists library provides more built-in functionality for list management, while angular-dragdrop requires more manual handling of drag and drop events. The former is better suited for complex scenarios, while the latter might be simpler for basic use cases.
:ok_hand: Drag and drop so simple it hurts
Pros of Dragula
- Framework-agnostic, works with any JavaScript project
- Lightweight and minimalistic, with a smaller footprint
- Extensive documentation and examples
Cons of Dragula
- Less Angular-specific features and integration
- May require more setup for complex Angular applications
Code Comparison
angular-dragdrop:
<div ng-model="list" jqyoui-droppable="{multiple:true}">
<div ng-repeat="item in list" ng-model="item" jqyoui-draggable="{index: {{$index}}}">
{{item.name}}
</div>
</div>
Dragula:
var drake = dragula([document.querySelector('#left'), document.querySelector('#right')]);
drake.on('drop', function (el, target, source, sibling) {
// Handle drop event
});
Summary
angular-dragdrop is specifically designed for AngularJS applications, offering tight integration with Angular's data binding and directives. It provides a more declarative approach to implementing drag and drop functionality.
Dragula, on the other hand, is a more versatile solution that can be used with any JavaScript project. It offers a simpler API and lighter footprint, but may require additional setup for complex Angular applications. Dragula's documentation and examples are more comprehensive, making it easier for developers to get started and troubleshoot issues.
Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
Pros of Sortable
- Framework-agnostic, works with any JavaScript project
- More extensive features, including multi-list sorting and nested lists
- Actively maintained with frequent updates
Cons of Sortable
- Steeper learning curve due to more complex API
- Larger file size, which may impact performance for simpler use cases
Code Comparison
angular-dragdrop:
$scope.dragOptions = {
start: function(e, ui) { ... },
stop: function(e, ui) { ... }
};
Sortable:
new Sortable(el, {
animation: 150,
ghostClass: 'blue-background-class',
onStart: function (evt) { ... },
onEnd: function (evt) { ... }
});
Summary
Sortable offers a more comprehensive solution for drag-and-drop functionality, supporting various frameworks and providing advanced features. It's actively maintained and has a larger community. However, it may be overkill for simple use cases and has a steeper learning curve.
angular-dragdrop is specifically designed for AngularJS applications, making it easier to integrate with Angular projects. It has a simpler API but lacks some advanced features and is less actively maintained.
Choose Sortable for complex, framework-agnostic projects, and angular-dragdrop for simpler AngularJS-specific implementations.
Beautiful and accessible drag and drop for lists with React
Pros of react-beautiful-dnd
- More comprehensive and feature-rich, offering advanced drag and drop capabilities
- Better performance and smoother animations, especially for larger lists
- Extensive documentation and community support
Cons of react-beautiful-dnd
- Specific to React, limiting its use in other frameworks
- Steeper learning curve due to its more complex API
- Larger bundle size, which may impact load times for smaller projects
Code Comparison
react-beautiful-dnd:
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
<DragDropContext onDragEnd={this.onDragEnd}>
<Droppable droppableId="list">
{(provided) => (
<div {...provided.droppableProps} ref={provided.innerRef}>
{/* Draggable items */}
</div>
)}
</Droppable>
</DragDropContext>
angular-dragdrop:
<ul ui-sortable="sortableOptions" ng-model="items">
<li ng-repeat="item in items" ui-draggable="true">
{{item.name}}
</li>
</ul>
The react-beautiful-dnd library offers a more declarative approach with specific components for different drag and drop elements, while angular-dragdrop uses directives to enable drag and drop functionality on existing elements.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Drag and Drop for AngularJS (with Animation)
Implementing jQueryUI Drag and Drop functionality in AngularJS is easier than ever with this wrapper for jQueryUI draggable/droppable components.
v1.0.13
- Allow to animate back on beforeDrop-cancel event if jqyouioptions.revertDuration is set
- Pass right context in case of CtrlAs syntax
- Add vertical sortable example in demo/dnd-insertInline.html
How to Use
-
bower install angular-dragdrop
(orsudo bower install angular-dragdrop --allow-root
) -
Reference
angular-dragdrop.min.js
in your application as:
<script src="components/angular-dragdrop/src/angular-dragdrop.min.js"></script>
- Resolve the dependency in the main module of your application as:
angular.module('myApp', ['ngDragDrop'])
- Drag anything as:
<span data-drag="true" jqyoui-draggable>So you think you can drag</span>
-
Finally, check out the cool demos
-
Note, use touchpunch.js to enable drag/drop on touch devices.
Angular Draggable options
- jqyoui-draggable â A custom angular attribute to make any element draggable. It holds more settings such as:
- index â number â $index of an item of a model (if it is an array) associated with it
- placeholder â boolean/string â If true, the place will be occupied even though a dragggable is moved/dropped somewhere else. If 'keep' is supplied, the original item won't be removed from the draggable.
- animate â boolean â If true, draggable will be animated towards droppable when dropped. If multiple is not set to true on droppable then its draggable will swap its position.
- onStart â string â callback method to be invoked (has to be defined in a controller) when dragging starts
- onStop â string â callback method to be invoked when dragging stops
- onDrag â string â callback method to be invoked while the mouse is moved during the dragging
- applyFilter - string - applies AngularJS $filter on the list before swapping items. Only applicable, if ngRepeat has any filter (such as orderBy, limitTo) associated with it.
- containment â string - position/offset. Offset by default. This forces to use jQuery.position() or jQuery.offset() to calculate proper position with respect to parent element or document respectively.
- deepCopy - boolean (optional) â If true, makes a deep copy of draggable that looses prototypical inheritance.
- beforeDrop â promise (optional) â Ask for confirmation before swapping. Works with both window.confirm and custom popup.
- insertInline â boolean(optional) â Make a list sortable. Same model is mandatory for draggable and droppable.
- direction â string(optional) â Property name that will be created on each scope to manage animation direction.
- data-drag â boolean â If true, element can be draggable. Disabled otherwise.
- data-jqyoui-options â object â should hold all the valid options supported by jQueryUI Draggable
- ng-model â string â An angular model defined in a controller. Should be a JS array or object
Angular Droppable options
- jqyoui-droppable â A custom angular attribute to make any element droppable. It holds more settings such as:
- index â number â $index of an item of a model (if it is an array) associated with it
- multiple â boolean â Requires to be true only if animate is set to true for draggable and to avoid swapping.
- stack â boolean â Requires if animate is set to true on draggable and if multiple draggables positioned one below the other
- onDrop â string â callback method to be invoked a draggable is dropped into the droppable
- onOver â string â callback method to be invoked when an accepted draggable is dragged over the droppable
- onOut â string â callback method to be invoked when an accepted draggable is dragged out of the droppable
- applyFilter - string - requires if both droppable as well as draggable share the same ngModel.
- containment â string - position/offset. Offset by default. This forces to use jQuery.position() or jQuery.offset() to calculate proper position with respect to parent element or document respectively.
- deepCopy â boolean (optional) â If true, makes a deep copy of droppable that looses prototypical inheritance.
- beforeDrop â promise (optional) â Ask for confirmation before dropping. Works with both window.confirm and custom popup.
- data-drop â boolean â If true, element can be droppable. Disabled otherwise.
- data-jqyoui-options â object â should hold all the valid options supported by jQueryUI Droppable
- ng-model â string â An angular model defined in a controller. Should be a JS array or object.
How to Contribute
- $ git clone https://github.com/codef0rmer/angular-dragdrop.git
- $ cd angular-dragdrop
- $ npm install --quiet -g karma-cli bower
- $ sudo npm install
- $ sudo bower install --force-latest
- $ npm test
Demo
Demo is here
v1.0.12
- Supports insertInline option to simulate sortable functionality.
- Relies on ngAnimate for sortable animation from left/right.
- Checkout the demo in demo/dnd-insertInline.html
v1.0.9 - breaking change
- Draggable and Droppable will not be deep copied by default unlike previous versions. Use
deepCopy
option if prototypical inheritance is not required. - Callbacks will not be executed forcefully within the context of scope which requires an extra digest loop for each event (start, stop, over, out, etc), especially drag that fires many times and running a digest loop is performance intensive in such scenario. Call
scope.$apply()
within callback, if needed.
v1.0.5 - breaking change
Do not pass evaluated expressions in callbacks. For example,
Before:
<div jqyoui-draggable="{onStart:'startCallback({{item}})'}">{{item.title}}</div>
After:
<div jqyoui-draggable="{onStart:'startCallback(item)'}">{{item.title}}</div>
Support
If you're having problems with using the project, use the support forum at CodersClan.
Top Related Projects
jQuery UI Sortable for AngularJS
Angular directives for sorting nested lists using the HTML5 Drag & Drop API
:ok_hand: Drag and drop so simple it hurts
Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
Beautiful and accessible drag and drop for lists with React
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot