Code Monkey home page Code Monkey logo

angular-sortable-view's Introduction

angular-sortable-view v0.0.12 Bower version

Fully declarative (multi)sortable for AngularJS

Demo: http://kamilkp.github.io/angular-sortable-view/

You can find the source code for this demo on branch "gh-pages".

Also see the changelog here

###DESCRIPTION:

This is a simple library written as a module for AngularJS for sorting elements in the UI. It supports both single elements list, and multiple connected lists, where an element can be moved from one to another.

This library requires no dependencies whatsoever (except angular.js of course), so you no longer need to include jQuery and jQueryUI and angularUI which altogether gives the size of around 340kB minified. Whereas the angular-sortable-view is only 5kB minified!.

###API:

The API is declarative. There are four directives (hooked on attributes) that need to be nested properly:

  • sv-root - this is where all the logic is happening. If multiple lists should be connected with each other so that elements can be moved between them and they have a common ancestor, put this attribute on that element. If not and you still want the multi-sortable behaviour a value for that attribue must be provided. That value will be used as an identifier to connect those roots together. Optional attributes:
    • sv-on-sort - The expression passed as a value of that attribute will be evaluated when elements order has changed after sorting. Several parameters can be injected there like: sv-on-sort="foo($item, $partFrom, $partTo, $indexFrom, $indexTo)" where:
      • $item is the item in model which has been moved
      • $partFrom is the part from which the $item originated
      • $partTo is the part to which the $item has been moved
      • $indexFrom is the previous index of the $item in $partFrom
      • $indexTo is the index of the $item in $partTo
    • sv-on-start - The expression passed as a value of that attribute will be evaluated when a user starts moving an element. Several parameters can be injected there like: sv-on-start="bar($item, $part, $index, $helper)" where:
      • $item is the item in model which started being moved
      • $part is the part from which the $item originates
      • $index is the index of the $item in $part
      • $helper is the jqLite/jQuery object of an element that is being dragged around
    • sv-on-stop - The expression passed as a value of that attribute will be evaluated when a user stops moving an element (drops it). This will be called regardless of the fact whether elements have been reordered or now. Several parameters can be injected there like: sv-on-end="baz($item, $part, $index)" where:
      • $item is the item in model which started being moved
      • $part is the part from which the $item originates
      • $index is the index of the $item in $part
  • sv-part - this attribute should be placed on an element that is a container for the ngRepeat'ed elements. Its value should be the same as the right hand side expression in ng-repeat attribute.
  • sv-element - this attribute should be placed on the same element as ng-repeat attribute. Its (optional) value should be an expression that evaluates to the options object.
  • sv-handle - this attribute is optional. If needed it can be placed on an element within the sortable element. This element will be the handle for sorting operations.
  • sv-helper - the element with this attribute will serve as a custom helper for sorting operations
  • sv-placeholder - the element with this attribute will serve as a custom placeholder for sorting operations

###Example of single sortable list

<div sv-root sv-part="modelArray">
	<div ng-repeat="item in modelArray" sv-element>
		<div>{{item}}</div>
	</div>
</div>

###Example of multiple sortable lists with common ancestor

<div sv-root>
	<div sv-part="modelArray1">
		<div ng-repeat="item in modelArray1" sv-element>
			<div>{{item}}</div>
		</div>
	</div>
	<div sv-part="modelArray2">
		<div ng-repeat="item in modelArray2" sv-element>
			<div>{{item}}</div>
		</div>
	</div>
</div>

###Example of multiple sortable lists without common ancestor

<div>
	<div sv-root="someUniqueId" sv-part="modelArray1">
		<div ng-repeat="item in modelArray1" sv-element>
			<div>{{item}}</div>
		</div>
	</div>
	<div sv-root="someUniqueId" sv-part="modelArray2">
		<div ng-repeat="item in modelArray2" sv-element>
			<div>{{item}}</div>
		</div>
	</div>
</div>

###Example of using handles

<div sv-root sv-part="modelArray">
	<div ng-repeat="item in modelArray" sv-element>
		<div>{{item}}</div>
		<span sv-handle>`
	</div>
</div>

###Example of using custom helpers per part

<div sv-root sv-part="modelArray">
	<div sv-helper>
		custom helper
	</div>
	<div ng-repeat="item in modelArray" sv-element>
		{{item}}
	</div>
</div>

###Example of using custom helpers per element

<div sv-root sv-part="modelArray">
	<div ng-repeat="item in modelArray" sv-element>
		<div sv-helper>
			custom helper {{item}}
		</div>
		{{item}}
	</div>
</div>

###Example of using custom placeholders per part

<div sv-root sv-part="modelArray">
	<div sv-placeholder>
		custom placeholder
	</div>
	<div ng-repeat="item in modelArray" sv-element>
		{{item}}
	</div>
</div>

###Example of using custom placeholders per element

<div sv-root sv-part="modelArray">
	<div ng-repeat="item in modelArray" sv-element>
		<div sv-placeholder>
			custom placeholder {{item}}
		</div>
		{{item}}
	</div>
</div>

angular-sortable-view's People

Contributors

cnlevy avatar dimchez avatar dsine-de avatar emilonlinester avatar evseevnn avatar kamilkp avatar pioug avatar

Watchers

 avatar  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.