Git Product home page Git Product logo

meteor-sortablejs's Introduction

Reactive reorderable lists with Sortable, backed by Meteor.js collections:

  • new elements arriving in the collection will update the list as you expect
  • elements removed from the collection will be removed from the list
  • drag and drop between lists updates collections accordingly

Demo: http://rubaxa-sortable.meteor.com

Issues

THIS PROJECT NEEDS A MAINTAINER.
If you encounter an issue while using this package, please CC @dandv when you file it in this repo.

Meteor

If you're new to Meteor, here's what the excitement is all about - watch the first two minutes; you'll be hooked by 1:28. That screencast is from 2012. In the meantime, Meteor has become a mature JavaScript-everywhere web development framework. Read more at Why Meteor.

Usage

Simplest invocation - order will be lost when the page is refreshed:

{{#sortable <collection|cursor|array>}}

Persist the sort order in the 'order' field of each document in the collection:

Client:

{{#sortable items=<collection|cursor|array> sortField="order"}}

Server:

Sortable.collections = <collectionName>;  // the name, not the variable

Along with items, sortField is the only Meteor-specific option. If it's missing, the package will assume there is a field called "order" in the collection, holding unique Numbers such that every order differs from that before and after it by at least 1. Basically, keep to 0, 1, 2, ... . Try not to depend on a particular format for this field; it is though guaranteed that a sort will produce lexicographical order, and that the order will be maintained after an arbitrary number of reorderings, unlike with naive solutions.

Remember to declare on the server which collections you want to be reorderable from the client. Otherwise, the library will error because the client would be able to modify numerical fields in any collection, which represents a security risk.

Passing options to the Sortable library

{{#sortable items=<collection|cursor|array> option1=value1 option2=value2...}}
{{#sortable items=<collection|cursor|array> options=myOptions}}

For available options, please refer to the main README. You can pass them directly or under the options object. Direct options (key=value) override those in options. It is best to pass presentation-related options directly, and functionality-related settings in an options object, as this will enable designers to work without needing to inspect the JavaScript code:

<template name="myTemplate">
  ...
  {{#sortable items=Players handle=".sortable-handle" ghostClass="sortable-ghost" options=playerOptions}}
</template>

Define the options in a helper for the template that calls Sortable:

Template.myTemplate.helpers({
    playerOptions: function () {
        return {
            group: {
                name: "league",
                pull: true,
                put: false
            },
            sort: false
        };
    }
});

Meteor-specific options

  • selector - you can specify a collection selector if your list operates only on a subset of the collection. Example:
Template.myTemplate.helpers({
   playerOptions: function() {
      return {
         selector: { city: 'San Francisco' }
      }
   }
});

Events

All the original Sortable events are supported. In addition, they will receive the data context in event.data. You can access event.data.order this way:

{{#sortable items=players options=playersOptions}}
Template.myTemplate.helpers({
    playersOptions: function () {
        return {
            onSort: function(/**Event*/event) {
                console.log('Moved player #%d from %d to %d',
                    event.data.order, event.oldIndex, event.newIndex
                );
            }
        };
    }
});

TODO

meteor-sortablejs's People

Contributors

rubaxa avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

meteor-sortablejs's Issues

Ability to override, cancel, preventDefault(), stopPropagation(), etc for onAdd insertion

Users need to be able to have some control over what the package attempts to do to their Collections. Being able to write custom onAdd functions are only so useful when there's no way to stop the default attempt at inserting a new document into the collection.

var newElementId = templateInstance.collection.insert(event.data);

That line causes problems, and often times is not the desired behavior. evt.stopPropagation(), evt.preventDefault(), and evt.cancelBubble = true all have no effect.

Meteor 'remove' doesn't updates the order numbers

In a sorted list with order numbers from (1,2 .. N), 'onSort' is amazing. It just updates the order number of items in the list. But, on removing or deleting an item from the list, the order number of elements next to deleted item are not changing. Not sure if it is expected condition or un-implemented, but it would be nice if the order numbers update on remove too.

Ex: 1 2 3 4 5 6 7 8
On remove : 5
Current order list: 1 2 3 4 6 7 8
Proposed order list: 1 2 3 4 5 6 7

order number does not get updated properly

When I reorder my list in meteor, the order fields are not updated properly. After a couple of times dragging and dropping they all end up at the same number. And there is also an internal server error.

This seems to be related to SortableJS/Sortable#398

I tried to apply the changes mentioned in the other issue. As I am not a meteor genius, I did not know how to apply the changes to the package.
Did anyone have the same issue?

before
screen shot 2016-02-16 at 18 54 12

after
screen shot 2016-02-16 at 18 57 06

server error
screen shot 2016-02-16 at 20 38 28

Atmosphere.js page points to wrong github

The Atmoshpere.js page still points to the main sortable github page, where posting an issue gets you nowhere except an eventual reply telling you to go submit the issue here.

Issue with npm install SortableJS in MeteorJS project

Could you tell me what may be the cause of the problem in installing sortable js with npm command? I see this error in JSON:

netx:~/workspace/app (master) $ meteor npm install sortablejs --save
npm ERR! Unexpected token } in JSON at position 11280
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/ubuntu/.npm/_logs/2018-12-06T10_09_36_253Z-debug.log

What the JSON file has that unexpected token?
The mentioned complete log does not give the file name:

0 info it worked if it ends with ok
1 verbose cli [ '/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/node',
1 verbose cli   '/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/npm',
1 verbose cli   'install',
1 verbose cli   '--save',
1 verbose cli   'sortablejs' ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session 0558a99e7e1cc796
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 http fetch GET 200 https://registry.npmjs.org/sortablejs 116ms
8 http fetch GET 200 https://registry.npmjs.org/sortablejs/-/sortablejs-1.7.0.tgz 33ms
9 silly pacote tag manifest for sortablejs@latest fetched in 224ms
10 silly install loadIdealTree
11 silly install cloneCurrentTreeToIdealTree
12 silly install loadShrinkwrap
13 silly saveTree app@
13 silly saveTree └─┬ @babel/[email protected]
13 silly saveTree   ├── [email protected]
13 silly saveTree   └── [email protected]
14 verbose stack SyntaxError: Unexpected token } in JSON at position 11280
14 verbose stack     at JSON.parse (<anonymous>)
14 verbose stack     at module.exports (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/lib/utils/parse-json.js:3:15)
14 verbose stack     at BB.join (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/lib/install/read-shrinkwrap.js:31:20)
14 verbose stack     at tryCatcher (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/bluebird/js/release/util.js:16:23)
14 verbose stack     at Holder$3._callFunction (eval at generateHolderClass (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/bluebird/js/release/join.js:92:16), <anonymous>:14:44)
14 verbose stack     at Holder$3.checkFulfillment (eval at generateHolderClass (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/bluebird/js/release/join.js:92:16), <anonymous>:29:30)
14 verbose stack     at Promise.eval (eval at thenCallback (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/bluebird/js/release/join.js:14:16), <anonymous>:6:20)
14 verbose stack     at Promise._settlePromise (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:566:21)
14 verbose stack     at Promise._settlePromise0 (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:614:10)
14 verbose stack     at Promise._settlePromises (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:693:18)
14 verbose stack     at Promise._fulfill (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:638:18)
14 verbose stack     at Promise._settlePromise (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:582:21)
14 verbose stack     at Promise._settlePromise0 (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:614:10)
14 verbose stack     at Promise._settlePromises (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:693:18)
14 verbose stack     at Promise._fulfill (/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/bluebird/js/release/promise.js:638:18)
14 verbose stack     at /home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/bluebird/js/release/nodeback.js:42:21
14 verbose stack     at /home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
14 verbose stack     at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
15 verbose cwd /home/ubuntu/workspace/app
16 verbose Linux 4.9.120-c9
17 verbose argv "/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/node" "/home/ubuntu/.meteor/packages/meteor-tool/.1.6.1_1.1pl6r72.bde6f++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/bin/npm" "install" "--save" "sortablejs"
18 verbose node v8.11.1
19 verbose npm  v5.6.0
20 error Unexpected token } in JSON at position 11280
21 verbose exit [ 1, true ]

Meteor: option not to update the collection

this is a repost of SortableJS/Sortable#530

My collections are never allowed to be modified on client.
I perform the reordering myself in the onSort hook so the UI works.

However I get errors because Sortable tries to update ordering:

Error invoking Method 'rubaxa:sortable/collection-update': Collection <pages> is not Sortable. Please add it to Sortable.collections in server code. [403] meteor.js:888:11
update failed: Access denied undefined

Would it be possible to add an option to prevent updating the collection?
Thanks,

Maintainers needed

I'm the original author of the Meteor integration integration for rubaxa:sortable.

Unfortunately I don't have much time nowadays to dedicate to this project. The code though is very well documented, so I hope that maintainers will be found.

Sortable client-side / null collection

is this a possibility with the current implementation of the package? I've been digging around the package, and things seem to break down when the collection name is null.

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.