-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Meteor sorting oddity... #287
Comments
I'm having the same issue. One thing to add is, the data is correctly saved to the database. If I reload the page, then items are shown sorted as expected. The issue is that the sorting seems to be applied twice: once on the client side by the sorting library, and once on the server side (the data is saved sorted, which triggers a reactive change on the client side). |
One more hack trying to make meteor work...
When you start dragging, save the order. When you end dragging, reset the order (and let the reactivity 'sort' things out). It shortly shows the incorrect state, which is ugly, but it works. |
I managed to avoid the blinking by creating a helper that gets executed when the data changes, and only in that moment is .sort(originalOrder) called. Still feels very much like a hack, but it works smoothly. |
I've experienced same problem. |
Same issue for me. I have a document in mongo with nested array of items and I want to sort them with Sortable, but after item is dropped the order becomes wrong :-( Unfortunately @hamoid's apporach does not work for me, at least I wasn't able to make it work. |
It looks like to make it work we should have an option which will prevent the final insertion of a node to another place in the DOM and will just trigger reactive stuff in meteor, which will change the order of items by himself... |
I just noticed that @hamoid's approach works if I have unique data-ids for the items, but unfortunately, in my case there could be no ids, cause that is just an array |
no way to use the array index as data-id? even if you don't save it to
the db? It would be just used to revert the sorting...
|
Guys, I've tried today few different ways to make it work with helper returning an array (without using stuff in rendered function). Nothing worked. Will try again within few days. Please let me know if you find any working solution. |
@hamoid yes, index as data-id works, too bad that spacebars do not support index out of the box.
|
@hamoid do you mean do it like that?
So that sortable.sort is called only when server-side update is done. |
Forget my words, it does not order items properly anyway. Crap. |
@dhampik This is what I'm doing now.
ps. gee, I must test sorting on mobile then! |
@hamoid You should reset originalOrder to null after using it.
Without this, at each update of the array content (say, one value of one field) the sort will be re-updated in some weird way. |
@renanlecaro You're welcome :) About your proposed change: what happens the second time you sort the list? originalOrder would be the null in that case, or? During my tests I did not notice any issues. But I'm no longer working on this... |
The onstart event recreates originalorder so it is not an issue ;) it seems Le ven. 18 sept. 2015 15:47, Abe Pazos notifications@github.com a écrit :
|
Dear all! Meteor is moved to the separate repository. If this issue is still actual, please create it there once again. For your info: this project needs a maintainer. |
The meteor repo wasn't able to help me. If anyone else has a method of using drag & drop to sort the array of a document, please tell me. After several hours of trying to preserve the old order of sortable, I gave up. Then, I realized I could preserve the sort order of my helper ... if this helps anyone ... here you go ... This is what my helper looked like. I have an array of media items with a weight property. Since I don't know how to sort this in the query, I'm doing it on the client side.
Then I realized that if I saved the result I could return the result in the same order as the first time the helper was run...
So, if I was reordering & saving anything this just returned the old result. The last trick was to have the Sortable.create in an autorun statement that also checked the lengths of these. So this is in an autorun statement.
|
So I have the following code in my template and corresponding javascript. My issue is that it seems that after moving a
productField
to a new position in the list, the update is sent to the server, which causes the DOM to reload, then Sortable "remembers" the change that was made and almost re-applies it. Causing the ordering on screen to be wrong. ie. theproductFields
aren't inindex
order.Is there a way I can "reset" the Sortable internal state back to "unsorted"?
Or is there a better way to achieve this!?
The text was updated successfully, but these errors were encountered: