Thursday, October 7, 2010

Re: Manually sorting items in a table - Doubly-Linked List vs sort_index

I'm assuming you are talking about the client facing site with html/
css/javascript. If that is the case,

A DOM tree is already a doubly linked list.

Elements are aware of their parent, their siblings and their children,
who are again aware of their parents, children and siblings.

All you should have to do is place the id as an attribute on the
corresponding element and use the DOM api to do the rest. Most
javascript libraries make doing that fairly easy to do now a days. no
sense trying to re-invent the wheel on this one.

you can use ajax to do an update after the user has made a change in
the UI, or make the click a save button to commit changes.

On Oct 6, 10:57 pm, Steven Sacks <stevensa...@gmail.com> wrote:
> I've got items in a list that a user can arbitrarily move around in
> whatever order they want.  Additionally, they can add a group of items
> to a list in a specific position within that list.
>
> Further, they can sort multiple items at once, meaning they can select
> one to many, sequential or non-sequential, and move them as a group to
> a new position in the list.
>
> The items will always be moved in order from top to bottom, so if you
> select multiple items, whether they're sequential or non, they will be
> flattened together into a group sequentially from the top to bottom.
>
> For example:
> [1, 2, 3, 4, 5]
>
> If I select 1, 4, and 5 and move them to where id 1 in the list is, it
> will look like this:
>
> [1, 4, 5, 2, 3]
>
> I need to refer to items not by their indices, but by their ids.  So,
> it's possible that a list might look like this (id-wise)
>
> [27, 31, 45, 7, 21]
>
> When I want to move items, I pass a before_id to determine which item
> they should move before. If I pass 0 for before_id, they are moved to
> the end of the list.
>
> I've got two possible choices here:
>
> 1) Doubly-linked list
>
> Each item in the list has a next_id and prev_id, which are foreign
> keys to the Model that those objects are. When I move items in the
> list, I calculate and modify the affected rows next/prev id fields.
>
> 2) sort_index
>
> A more brute force method is to have each item in the list have a
> sort_index, and when I add/move items to the list, I determine where
> they're supposed to go and calculate the sort_index for every row in
> the table. This actually isn't as easy as it seems because you can't
> Array.insert on a QuerySet.  I'm leaning towards a doubly-linked list.
>
> Does anyone have any advice or other, more efficient ways of
> accomplishing this?
>
> Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate