[Betternestedset-talk] Sortable Sets
Jeremy Nicoll
jnicoll at gnexp.com
Wed Mar 19 15:45:29 EDT 2008
Hello John-Paul,
I've done this in a recent project. Basically the way I do it is
check to see what order the a selected item in a list is in, and then
move that item before/after a child node in the target parent based off
this information. It's a bit complicated, but it's doable. I monkey
patched the module SymetrieCom::Acts::NestedSet to include the following
method to help me with this scenario:
------------------------------------------------------------------------
def move_to_parent_location(parent, location)
parent = nil if parent == 0
parent = parent === self.class ? parent :
self.class.find(parent) if parent
children = parent ? parent.children : self.class.roots
if children.length > 0
ord = location.to_i
if ord > children.length
self.move_to(children.last, :right)
elsif children[ord] != self
self.move_to(children[ord], :left)
end
elsif parent
self.move_to(parent, :child)
end
end
------------------------------------------------------------------------
*Jeremy Nicoll*
www.gnexp.com <http://www.gnexp.com>
(801) 783-3831
John-Paul Bader wrote:
> Hey there,
>
> I just subscribed so i hope this question isn't redundant.
>
> I'm trying to implement a sortable nested set.
>
> I've already got an application with better_nested_set in place. I
> also got a nice nested <ul> rendering for my tree. No I'd be able to
> drag an drop / sort elements across the set.
>
> I found this Wiki entry which says that it wouldn't be a good idea in
> general to use sortable.create with :tree => true
>
> http://whynotwiki.com/Rails_/_Sortable_trees
>
> On the same page there is a link to the rubyonrails wiki stating that
> there is a fix expecially for better_nested_set. http://dev.rubyonrails.org/ticket/7807
>
> My question would be what your experiences are. Is there a good way to
> implement a sortable / draggable better_nested_set ? If not do you
> have any suggestions, thoughs on this ?
>
> Thanks and kind regards,
>
> John (Berlin / Germany)
> _______________________________________________
> Betternestedset-talk mailing list
> Betternestedset-talk at rubyforge.org
> http://rubyforge.org/mailman/listinfo/betternestedset-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080319/cf89fb10/attachment-0001.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: logo_sig.jpg
Type: image/jpeg
Size: 2312 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080319/cf89fb10/attachment-0001.jpg
More information about the Betternestedset-talk
mailing list