Coder Social home page Coder Social logo

angular-sortable's Introduction

angular-sortable

Very simple jquery-ui like sortable that does not require jquery-ui... Look further to see the features that are not implemented yet :)

Demo: http://sebastien.chartier.pro/angular-sortable

Plunker: http://plnkr.co/edit/L33H0T?p=preview

I am trying to make the best sortable directive for Angular.js, your contribution is very welcome :)

I figured out that when we detect that the order should be updated, instead of proceeding to complex DOM manipulations, updating the referenced array would produce the same result, the "Angular" way (this is my personal opinion)...

Installation

bower install angular-sortable --save

Usage

<ul ng-sortable="items">
        <li ng-repeat="item in items" class="sortable-element" ng-style="{backgroundColor: item.color}">
            {{item.name}}, {{item.profession}}
        </li>
    </ul>

IMPORTANT: Sortable elements are identified with the class "sortable-element".

Related attributes

Options are defined as tag attributes:

  • ng-sortable (required) : The value for this attribute must be the same list used by the inner ng-repeat that create the sortable elements.
  • ng-sortable-on-change (optional)
  • ng-sortable-on-dragstart (optional)
  • ng-sortable-on-dragend (optional)
  • ng-sortable-on-drag (optional)

Example

HTML:

<ul ng-sortable="items"
    ng-sortable-on-change="onItemsChange"
    ng-sortable-on-dragstart="onItemsDragstart"
    ng-sortable-on-dragend="onItemsDragend"
    ng-sortable-on-drag="onItemsDrag">
    
    <li ng-repeat="item in items" class="sortable-element" ng-style="{backgroundColor: item.color}">
      {{item.name}}, {{item.profession}}
    </li>
</ul>

Controller

    $scope.onItemsDrag = function(event) {
        // Do whatever you want here...
        console.log('onItemsDrag');
    };

    $scope.onItemsDragstart = function(event) {
        // Do whatever you want here...
        console.log('onItemsDragstart');
    };

    $scope.onItemsDragend = function(event) {
        // Do whatever you want here...
        console.log('onItemsDragend');
    };

    $scope.onItemsChange = function(fromIdx, toIdx) {
        // Do whatever you want here...
        console.log('onItemsChange');
    };

Important features missing in this component

Not sure about features

  • Should we integrate with Bootstrap or keep styling to a minimum?

Your ideas are welcome, don't hesitate to contact me at [email protected] :)

angular-sortable's People

Contributors

schartier avatar

Watchers

 avatar

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.