GithubHelp home page GithubHelp logo

lynzz / vue.draggable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sortablejs/vue.draggable

0.0 2.0 0.0 366 KB

Vue component allowing drag-and-drop sorting in sync with View-Model. Based on Sortable.js

License: MIT License

JavaScript 100.00%

vue.draggable's Introduction

Vue.Draggable

GitHub open issues GitHub closed issues Npm download Npm version Package Quality MIT License

Vue component (Vue.js 2.0) or directive (Vue.js 1.0) allowing drag-and-drop and synchronization with view model array.

Based on and offering all features of Sortable.js

##Demo

demo gif

##Features

  • Full support of Sortable.js features
  • Keeps in sync view model and view
  • No jquery dependency

##For Vue.js 2.0

Use draggable component:

<draggable  :list="list" :options="{group:'people'}" @start="dragging=true" @end="dragging=false">
   <div v-for="element in list">{{element.name}}</div>
</draggable>

Props

list

Type: Array
Required: false
Default: null

Array to be synchronized with drag-and-drop. Typically same array as refrenced by inner element v-for directive.
Note that draggabe component can be used with a list prop

options

Type: Object
Required: false

Option used to inicialize the sortable object see: sortable option documentation
Note that all the method starting by "on" will be ignored as draggable component expose the same API via events.

clone

Type: Function
Required: false
Default: (original) => { return original;}

Function called on the source component to clone element when clone option is true. The unique argument is the viewModel element to be cloned and the returned value should be its cloned version.
By default vue.draggable reuse the viewmodel element, so you have to use this hook if you want to clone or deep clone it.

Events

start, add, remove, update, end, choose, sort, filter, move, clone
Called when there equivalent onStart, onAdd, .... are fired by Sortabe.js with the same argument.
See here for reference

###Fiddle Simple: https://jsfiddle.net/dede89/sqssmhtz/

Two Lists: https://jsfiddle.net/dede89/32ao2rpm/

Example with list clone: https://jsfiddle.net/dede89/t3m5krea/

##For Vue.js 1.0

Use it exactly as v-for directive, passing optional parameters using 'options' parameter. Options parameter can be json string or a full javascript object.

<div v-dragable-for="element in list1" options='{"group":"people"}'>
  <p>{{element.name}}</p>
</div>

###Limitation

  • This directive works only when applied to arrays and not to objects.
  • onStart, onUpdate, onAdd, onRemove Sortable.js options hooks are used by v-dragable-for to update VM. As such these four options are not usable with v-dragable-for. If you need to listen to re-order events, you can watch the underlying view model collection. For example:
        watch: {
            'list1': function () {
                console.log('Collection updated!');
            },

###fiddle Simple: https://jsfiddle.net/dede89/j62g58z7/

Two Lists: https://jsfiddle.net/dede89/hqxranrd/

Example with list clone: https://jsfiddle.net/dede89/u5ecgtsj/

Installation

  • Available through:
 npm install vuedraggable
 Bower install vue.draggable

Version 1.0.9 is Vue.js 1.0 compatible
Version 2.0.2 is Vue.js 2.0 compatible

  • For Modules

    // ES6
    //For Vue.js 2.0
    import draggable from 'vuedraggable'
    ...
    export default {
          components: {
              draggable,
              ...
          }
          ...
    
    //For Vue.js 1.0 only
    import VueDraggable from 'vuedraggable'
    import Vue from 'vue'
    Vue.use(VueDraggable)
    
    // ES5 
    //For Vue.js 1.0
    var Vue = require('vue')
    Vue.use(require('vuedraggable'))
    
    //For Vue.js 2.0
    var draggable = require('vuedraggable')
  • For <script> Include

    Just include vuedraggable.min.js or 'vue.dragable.for' after Vue.
    lodash(version >=3) is needed only for Vuejs. 1.0 version of the library.

vue.draggable's People

Contributors

cgarnier avatar david-desmaisons 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.