Git Product home page Git Product logo

angular-legacy-sortablejs's Introduction

angular-legacy-sortable

Angular 1 module that integrates with Sortable.js

Installation

Install with NPM

npm install angular-legacy-sortablejs-maintained

Install with Yarn

yarn add angular-legacy-sortablejs-maintained

Don't install the old angular-legacy-sortablejs package as thats not maintained

Examples

Live Demo

Simple Drag and Drop

angular.module('exampleApp', ['ng-sortable'])
.component('dragAndDropExample', {
  template: `<ul ng-sortable>
    <li ng-repeat="item in ['burgers', 'chips', 'hotdog']">
      {$ item $}
    </li>
  </ul>`,
})

Specifying a Config

You can pass a Config obj to ng-sortable and it will pass this onto the created sortable object. The available options can be found here

angular.module('exampleApp', ['ng-sortable'])
  .component('dragAndDropExample', {
    template: `
    <ul ng-sortable=$ctrl.sortableConf>
      <li ng-repeat="item in ['burgers', 'chips', 'hotdog']">
        {$ item $}
      </li>
    </ul>`,
    controller: class ExampleController {
      constructor() {
        this.sortableConf = {
          animation: 350,
          chosenClass: 'sortable-chosen',
          handle: '.grab-handle',
          forceFallback: true,
        };
      }
    },
  });

Drag handle

Example showing how use the handle option

angular.module('exampleApp', ['ng-sortable'])
  .component('dragAndDropExample', {
    template: `
    <ul ng-sortable=$ctrl.sortableConf>
      <li ng-repeat="item in ['burgers', 'chips', 'hotdog']" draggable="false">
        <span class="grab-handle">Drag Header</span>
        <div>{$ item $}</div>
      </li>
   </ul>`,
   controller: class ExampleController {
      constructor() {
        this.sortableConf = {
          animation: 350,
          chosenClass: 'sortable-chosen',
          handle: '.grab-handle',
          forceFallback: true,
        };
      }
    },
  });

Tests

There are selenium based tests that can be used to check for regressions

Requirements

  • node
  • yarn

Setting up tests

Navigate to the repo directory in a terminal and run

yarn

Running e2e tests

To run the e2e tests run each of these commands in a separate terminal window

npm run serve:example
npm run webdriver
npm run test:e2e

angular-legacy-sortablejs's People

Contributors

doxiaodong avatar rubaxa avatar samjacobclift avatar sergeykhodussov avatar stevebeller avatar tplaner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

angular-legacy-sortablejs's Issues

Better Docs

Could we perhaps have some better doc's?

I'd be more than willing to write some up and help out but do we have any preferences in how/where they should be written? Perhaps a github page

Nested ng-sortable is not working

I'm trying to use ng-sortable inside a directive that is using ng-sortable like:

directive1:

ng-sortable 
    ng-repeat(list1)
      directive2

directive2

   ng-sortable
      ng-repeat(list2)

directive1 is working fine, the list is ordered as expected, but on directive2 when trying to order (dragging/dropping) its changing the order going back to the original position. If I remove the ng-sortable config on directive1 the directive2 start working.

Any idea?

ng-repeat isn't actualized after using ng-sortable

ng-repeat isn't actualized after using ng-sortable,

For exemple:

 <tbody ng-sortable="vm.sortableConfig" ng-repeat="(key, value) in array">
    <tr>{{key}}</tr>
</tbody>

The result before using sortable:
1
2
3

The result for exemple after using sortable:
2
1
3

The result wanted after using sortable:
1
2
3

Apparently, ng-repeat isn't informed from ng-sortable. The key from ng-repeat isn't updated.
Have you a solution for this problem ? Thank you in advance.

Not available with npm install

I installed this package with npm. npm install -S angular-legacy-sortablejs.
but it occurs error below.

Module not found: Error: Cannot resolve module 'angular-legacy-sortablejs' in /home/myproject/src/

May be because of require('./Sortablejs')

I think that published package to npm is older than github#master.
Please republish.

thanks.

ng-sortable.js:84 Uncaught TypeError: Cannot read property

Error fires on drag event if one of these functions: onStart(), onEnd(), onDrag()... etc. was declared in ng-sortable configs.

This error is triggered because variable: var source = getSource(); got undefined in function: _emitEvent(evt) file ng-sortable.js at line 79.

My solution was: ng-sortable.js file, change function _emitEvent()
delete lines 84 and 85 so function now looks like:
function _emitEvent(/**Event*/evt, /*Mixed*/item) { var name = 'on' + evt.type.charAt(0).toUpperCase() + evt.type.substr(1); var source = getSource(); /* jshint expr:true */ options[name] && options[name]({ oldIndex: evt.oldIndex, newIndex: evt.newIndex }); }

deprecation

Should this branch be deprecated in favour of any of the available forks?

I don't know who's keeping this branch up to date.

Error when dropping an item with nested list into a another item with nested list

Consider the following case:

  • item 1
    • subitem 1
  • item 2
  • item 3
    • subitem 2

If both the main list and sublists are connected then root items can be normally sorted each other and item 2 can be dragged to subitem of item 1 or item 3.

However, if you drag item 3 as subitem of item 1, i.e. aiming to get the following:

  • item 1
    • subitem 1
    • item 3
      • subitem 2
  • item 2

then there will be the following error (and the subitem 2 will not be shown):

Sortable.js:1823 Uncaught TypeError: Cannot read property 'Sortable1551478014931' of null
    at _dispatchEvent (VM1983 Sortable.js:1823)
    at Sortable._onDrop (VM1983 Sortable.js:1446)
    at Sortable.handleEvent (VM1983 Sortable.js:1527)

A bit of debugging showed that ng-sortable triggers destroy which deletes, I believe, the sortable of the dragging item i.e. item 3.

Here is a minimal codepen demo.

This might be related to #43

array length is changing

Hello,

Thanks for nice work.

I have an issue.
After dragend (onSort), the numbers of items are increasing.
I also tried dev, still no luck.
Any help will be appreciated!

Thank you,

Mudin

Model on the event gets stuck to item moved to/from nested list

I've discovered another bug with the case of nested list.

If we consider the list like this

  • item 1
    • subitem 1
  • item 2
  • item 3

As long as you move items in the main list all will be fine. However, once you move item (e.g. item 2) to nested list all following moves will have event.model set to item 2. In other words, if you then try to move item 3 above item 1 the move will succeed, however in callbacks (e.g. onEnd) the event.model will be wrong.

The same is true if the first action is moving an item from from the nested list (e.g. subitem 1). All following moves will have subitem 1 set as the model.

Here's minimal codepen showing the problem.

Buggy when filters are used in ng-repeat

Beware when using event.model if you have filters on your ng-repeat directive. SortableJS will report the wrong item in event.model. You will need to find the correct item manually using the event.oldIndex and/or the event.newIndex properties.

Also beware that when using filters, the event.models array comes in the old sort order, not the new one. Without using filters, the new sort order array is passed properly.

support sortablejs 1.6.0

Hi

Sortablejs released version 1.6.0 which fixes a memory leak, however, the angularjs version requires v1.5.x

When are you planning on releasing a version that works with 1.6.0 ?

Thanks

onMove not work

html

<ul class="news-tag-list" ng-sortable="vm.customSortableConf">
                <li id="{{item.label}}" ng-repeat="item in vm.customSortableList" ng-click="vm.customItemClick(item)" ng-class="{'fixed':item.fixed&&vm.showEditButton}">
                    <div>{{item.label}}</div>
                </li>                
</ul>

controller.js

var vm={};
vm.customSortableConf={
                group:{
                    name:"custom",
                    put:"allCategory"
                },
                filter: ".fixed",
                disabled:true,
                sort: true,
                onMove:function(evt){
                    console.log(evt);
                    return evt.related.className.indexOf('fixed') === -1;
                }
            };

When I move the item, the onMove function is not called.Why?

Webpack not resolving Sortable.js correctly

I'm learning webpack, so hopefully I'm not doing something stupid --

Shouldn't this project require Sortable as sortablejs instead of ./Sortable, since it's no longer in the main Sortable repository?

If so, I can make a PR. :)

Thanks for the hard work.

In multiple lists, does not remove the previous "pull" item from data model

Your examples show moving between pre-existing DOM elements in multiple lists, but in Angular all DOM elements are generated via the data model.

When moving from one list to another, it succeeds moving the DOM item and the data item, BUT it does not remove it from the previous data list. The previous list reappears as if cloned. It doesn't appear to know to remove from the data model which would certainly be an Angular specific thing.

I had to plug into onRemove: and do a dirty check of the removed evt.model attribute (ie: id) from the actual scope variable.

$scope.manyLists = [[{id:1}],[{id:2}],[{id:3}]];

<my-dir items="manyLists[0]"></my-div>
<my-dir items="manyLists[1]"></my-div>
<my-dir items="manyLists[2]"></my-div>

Will this be solved by #36?

Failed to execute 'removeChild' The node to be removed is not a child of this node.

At first I tought my error was similar to #23 but it's a bit different.

Basically, this happens when I try to use the put/pull method defined within the group params when working with nested sorting so I can move from one nested sorting list to another nested sorting list.

This is the error:

Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
at _sync (angular-legacy-sortable.js:118:46)
at a.onAdd (angular-legacy-sortable.js:172:33)

This is what my config looks like:

vm.list = [
    {id: 1, name: 'Name of item 1',
        gallery: [
            {id: 1, name: 'Name of image 1'},
            {id: 2, name: 'Name of image 2'},
            {id: 3, name: 'Name of image 3'}
        ]
    },
    {id: 2, name: 'Name of item 2', 
        gallery: [
            {id: 1, name: 'Name of image 1'},
            {id: 2, name: 'Name of image 2'},
        ]
    },
    {id: 3, name: 'Name of item 3', gallery: []}
];

And use it like this:

<ul ng-sortable>
    <li ng-repeat="item in vm.list track by item.id">
        <p>{{item.name}}</p>
        <ul ng-sortable="{group: {name:'child', put: true, pull:true} }">
            <li ng-repeat="gallery in item.gallery track by gallery.id">
                <p>{{gallery.nome}}</p>
            </li>
        </ul> 
    </li>
</ul>

I also tried to define the nested sortable item as follow:

<ul ng-sortable="{group: {name:'child{{item.id}}', put: true, pull:true} }">

//or
<ul ng-sortable="{group: {name:'child{{item.id}}', put: 'child{{item.id}}', pull:true} }">

Both give me the same end result, wich is the error and then stop working 100%.

Delayed drag instantly canceled on chrome mobile

When the delay configuration is set to a value greater than zero, the _disableDelayedDrag function is called almost instantly after _prepareDragStart by a mousemove event. This causes the drag and drop to be not useable.

This problem occurs in chrome on android.
Chrome version: 63.0.3239.11
Android version 8.0.0

error when change browser tab and this problem only happens with Chrome

the following error message appears in the console :

Error in event handler for runtime.onMessage: TypeError: Cannot read property 'val' of undefined
at Object.cipEvents.triggerActivatedTab (chrome-extension://oakpnnaknlicjghpchokjoelhfjnmhcd/rdmchrome.js:2313:14)
at chrome-extension://oakpnnaknlicjghpchokjoelhfjnmhcd/rdmchrome.js:61:14

this error appear when I change of browser tab and only happens in Chrome browser.

I am using sortable with angular

"angular": "1.6.4",
"sortablejs": "^1.5.1"
"angular-legacy-sortablejs-maintained": "^0.5.2"

Doesn't work with ng-if

If applying ng-sortable on an element which also has ng-if, the plugin causes an error:

Cannot create property 'stack' on string 'Sortable: `el` must be HTMLElement, and not [object Comment]'

I presume because it's getting the comment node that Angular inserts for the ng-if handling.

Update npm

Update npm, please.
You have require('./Sortable') instead require('sortablejs') there

two elements sorting problem

When there're two elements,then after three times of exchanging, there will be a bug:

angular.min.js:103 Error: Failed to execute 'insertBefore' on 'Node': The new child element contains the parent.
    at Comment.<anonymous> (jquery-1.8.2.min.js:2)
    at init.domManip (jquery-1.8.2.min.js:2)
    at init.after (jquery-1.8.2.min.js:2)
    at Object.enter (angular.min.js:176)
    at Object.move (angular.min.js:176)
    at angular.min.js:235
    at Object.fn (angular.min.js:122)
    at l.$digest (angular.min.js:123)
    at l.$apply (angular.min.js:126)
    at Sortable.onEnd (ng-sortable.js:141)

and in the first of exchanging, the callback parameter evt return the wrong order in evt.models.

ng-sortable is not working after button is clicked

I have a list of editable inputs that is sortable using ng-sortable. For example,

<div ng-sortable>
    <div ng-repeat = question in question_list>
        <input type="text" ng-model = "question">
    </div>
</div>

When someone change the text in the input, the list of inputs is no longer sortable by dragging. I have the same problem if the input is a button as well. If someone clicks on the button, the list of buttons is also no longer sortable by dragging.

What do you think is the problem?

don't work with angular material

view code is like this

<div ng-sortable="sortable">
  <div ng-repeat="app in apps track by app.id">
    <md-list-item ng-click="showSettingDialog(app)" class="list-item">
      <img ng-src="{{'images/social/plugin-icon-'+app.type+'.png'}}" class="list-img"/>
      <p style="margin-left: 12px;">{{ app.typeName }}</p>
      <span ng-click="del(app, $event)" class="list-item-del" style="cursor: pointer;display: none;margin-top: 10px;">
        <i class="material-icons">delete</i>
      </span>
    </md-list-item>
  </div>
</div>

but when drag item of list, the whole page is show on the page, how this happen ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.