Skip to content

Reorder item inside a list #155

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

Closed
FrancescoMussi opened this issue Feb 9, 2015 · 8 comments
Closed

Reorder item inside a list #155

FrancescoMussi opened this issue Feb 9, 2015 · 8 comments
Labels

Comments

@FrancescoMussi
Copy link

Hello.
Sorry if is not the right place to ask.
How is possible to reorder items inside a list using angular-dragdrop?

Here is my stack overflow question:

http://stackoverflow.com/questions/27799766/angular-dragdrop-how-to-reorder-items

@codef0rmer
Copy link
Owner

Unfortunately, It's not possible as of now, you have to use ui-sortable instead. I'm in the process to implement sorting in angular-dragdrop but do not want to give any false commitment.

@Psabot
Copy link

Psabot commented Mar 1, 2015

Hi,

I don't know if I understood your issue very well but I think I had the same.
I wanted to be able to drag&drop one element above or below another.
To achieve that, I modified a little bit the angular-dragdrop.js.

The idea was to get the offset of my draggable and compare it to the other element list offset.
I did the edit in the mutateDroppable method.
Here's the sample :

for(var i = 0; i <= dropModelValue.length; i++)
{
var elmPos = $('#divid').children().eq(i).offset().top;
if (currentDraggableYPos < elmPos)
elemToInsert = i;
}
Just dive into your droppable and looking for the right place.

"elemToInsert" is the index of the new the element you just dropped.
To insert it in the array, just do :
dropModelValue.splice(elemToInsert, 0, dragItem); instead of dropModelValue.push(dragItem);.

Hope this could help

@FrancescoMussi
Copy link
Author

oh thank you very much!
Monday morning i will try it!
If it works i will really build a sculpture in your honor!

@Psabot
Copy link

Psabot commented Mar 3, 2015

Notice that it's not an optimal solution because it's not very accurate since I just get the top position.
But you can easily improve it.
However, it should fix your issue for now.

Did you try it ?

@r4hulp
Copy link

r4hulp commented Mar 4, 2015

@Psabot how can we retrieve elemToInsert i.e. index of new element? I am kinda confused here. I also badly want to implement sorting :(

edit : arghhh got it... I can not deal with ID selector won't be an efficient solution for me ;-(

@Psabot
Copy link

Psabot commented Mar 4, 2015

@rahulrulez You just need only one id on the container. Why can't you deal with it ?
In fact you just need an identifier to grab your container in the DOM.

@codef0rmer
Copy link
Owner

@Psabot : I'm half-way done with insertInline option but still figuring out how to do animations with ngAnimate. Take a look at: bbb6ea7

@loverdrive
Copy link

@codef0rmer : is there any news about insertInline option?
Thank you for your work!

codef0rmer pushed a commit that referenced this issue Sep 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants