This plugin is no longer maintained. Please use another sorting plugin for EmberJS, like Ember Sortable.
An Ember 1.13+ component for jQuery UI's Sortable Widget. This addon is a fork of ivy-sortable.
As an ember-cli addon:
ember install ember-ui-sortableThis addon provides two components for your sorting pleasure.
{{#ui-sortable}}...{{/ui-sortable}}takes an array of thingies (technical term) and spits out a sortable list.{{#ui-draggable}}...{{/ui-draggable}}can wrap around anything you want to drag around your UI like a dirty blanket. Using theconnectToSortableoption, you can plop this draggable in a sortable and win all the prizes.
Use the ui-sortable component block to iterate over the wrapped content:
This will output a sortable list, and dragging and dropping items will reorder them in the passed in content array. To handle an action on the parent controller or component, you can bind an action to the moved property. The moved action will return three arguments, the object being moved, the previous index, and the new index.
Following the principle of Data Down Actions Up (DDAU), the sortable component doesn't modify the content array. You'll need to do it yourself with the action bound to moved.
Handle this action like so...
// controller|component.js
export default {
actions: {
movedPerson: function(person, oldIndex, newIndex) {
// do rad stuff...ajax or something
// Here's an example, where model is an array of something
const content = this.get('model');
content.removeAt(oldIndex);
content.insertAt(newIndex, person);
return content.save();
}
}
}Add a connectWith option to allow dragging items between lists! Make a Trello clone, or something. Be awesome.
{{#ui-sortable class="connected" connectWith=".connected"}}...{{/ui-sortable}}
{{#ui-sortable class="connected" connectWith=".connected"}}...{{/ui-sortable}}The following jQuery UI Sortable options are supported:
axisappendToconnectWithcontainmentcursorAtcursordelaydisableddistanceforceHelperSizeforcePlaceholderSizegridhandlehelperopacityplaceholderrevertscrollSensitivityscrollSpeedscrolltolerancezIndex
Use the ui-draggable component block to wrap something else and make it draggable:
Add an optional connectToSortable property to allow dragging this element to a ui-sortable list. #winning.
The following jQuery UI Draggable options are supported:
addClassesaxisappendToconnectToSortablecontainmentcursorAtcursordelaydisableddistancegridhandlehelperopacityrefreshPositionsrevertrevertDurationscrollSensitivityscrollSpeedscrollsnapsnapModesnapTolerancestackzIndex
- Demo app
- Droppable component. Why not?
¯\_(ツ)_/¯
Fork this repo, make a new branch, and send a pull request. Make sure your change is tested or it won't be merged.
To run tests:
git clone # <this repo>
npm install
npm testOr, to start a test server that continually runs (for development):
ember test --server