Comments (16)
You can get the item elements in their order with .getItemElements()
see http://packery.metafizzy.co/faq.html#order-after-drag If you wish to manipulate the items in their order, you can access them in pckry.items
.
If you could provide a reduced test case I might be better enabled to answer your request. See Submitting Issues in the contributing guidelines.
from packery.
I extended your demo here (http://codepen.io/magrolino/pen/upral) - it saves the values of the tabindex attribute to an array and saves the array to localStorage. I am stuck now loading at the page and trying to re-order the element array before applying the packery layout.. This would have been nice so end-user changes in the layout could be 'saved' on the enduser-side..
Edit: for some weird reason I cannot run the demo in firefox, nor in chrome with private browsing enabled the localStorage call seems to throw some issues with codePen / iFrames.. hope you can still see what I mean.
from packery.
Thanks so much for the test case!
See my fork http://codepen.io/desandro/pen/wtafg
Here's what I'm doing
- Disable initial layout with
isInitLayout: false
- If the sortOrder is available via localStorage, then edit
pckry.items
to match that order - trigger
pckry.layout()
Here's another version of it http://codepen.io/desandro/pen/cGhJt I'm adding a special custom method sortItems
which accepts an array and a function in order to sort the items. It's all make-shift, but it works given your example
For others looking at this example: This is just one way to get it done. The take-away is, you can retrieve the items in order with getItemElements
and then you can manipulate them in pckry.items
. I can see how something like .sortItems()
could be useful. Speak up if you're trying to do something similar and having trouble.
from packery.
awesome, thanks so much for the answer/help!
from packery.
Hallo desandro,
thanks for your help. But I got some ajax problems with
var container = document.querySelector('#container');
so I switched to jQuery now
var
But now i dont how to access the old pckry.items?
I can get the elements:
var elems = $container.packery('getItemElements');
But I cant set the reordered elements. Remove and adding results in problems.
You got a hint for me?
Thanks in advance!
Cheers,
Matthias
from packery.
@mfrosch You can access the Packery instance with $container.data('packery').
var pckry = $container.data('packery');
from packery.
Hi desandro,
thanks for your quick help!
I already tried "var pckry = Packery.data( $container );" instead of "var pckry = $container.data('packery');"
facepalm : )
Thanks and Cheers,
Matthias
from packery.
So close! var pckry = Packery.data( $container[0] );
would have worked too
from packery.
Here's a version with jQuery http://codepen.io/desandro/pen/GcDbr
from packery.
Hello desandro,
I'm very used to jQuery but I'm using it with packery.
With your last example: http://codepen.io/desandro/pen/GcDbr, how would I change the text of each item like in this example : http://codepen.io/desandro/pen/mdJnF
I tried to use the content of the localStorage but in vain.
In fact I need that for one of my client. Each item comes from a database and my client wants to be able to drag the position of each item at his convenience and then save each new position back in the database.
So for each item, when I validate my form, I need the initial position, and the final position of each item.
Hope you'll be able to help me. I also hope I'm clear enough ...
Thanks !
from packery.
Reopening, others have have asked for this consistently. I'm thinking about adding it to the docs.
from packery.
Sounds good. For your information. Currently after drag I count the items and set a number to each item. Those numbers I save via ajax in database and reuse them. If you like I could try to get time for a reduced test case.
Currently I'm thinking about a solution for reusing the sort order in combination with sticky items which should be always on the same place. Or is there already some example for this?
Thanks and cheers,
Matthias
from packery.
I have a problem, because I use animate item size on click event, so when I use draggie item change state(expands/collapse). In the same time I'd like to reorder item data.
I'd like to get element data on drag start event, so I can remember item state on drag start and recreate that state on dragend or dragitempositioned event. Or I would like to set off classie on drag start and then set classie on when dragitempositioned event is fired. Anyway, I'd like to access dragstart event of draggie. Can you please help me to achieve this goal? Thanks in advance for any hint.
Best regards, Milan
from packery.
I've succeeded to trap this with "is-positioning-post-drag" class, which I check in click event, so consider this resolved.
BR, Milan
from packery.
how can i save layout using packery and retrieve the original layout.
from packery.
Packery v2 has new drag behavior, which requires a new technique to save & restore drag position. Closing this issue here, picking it up in #337
from packery.
Related Issues (20)
- Some elements are not being placed in 2 columns everytime
- Bug while open packery galery on Ipad
- How do i sort by tabindex?
- Custom Drop Zone : How to define a different drop zone. HOT 1
- Saving the order in the database HOT 1
- How to prevent grid size from expanding when dragging an item outside of its current dimensions? HOT 3
- Packery results in significant cumulative shift score HOT 3
- access gaps array with jQuery init HOT 1
- Activation of the packery without changing the positions of the layouts HOT 2
- laravel mix/webpack ERROR Module not found: Error: Can't resolve 'jquery' HOT 2
- Let user leave gaps between tiles and disable stacking stamped items (packery 2 or 1)
- How can I fix the size of the canvas?
- Packery and Livewire with pagination
- rowHeight set to tallest item
- React with Packery some strange issues
- Appended and Prepended with ImagesLoaded
- packery draggabilly: prevent from dropping over a .stamp.non-drop item. HOT 2
- dragItemPositioned no longer triggering HOT 1
- Draggable with custom (user inputted) elements HOT 1
- Feature request: Rotate items
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from packery.