save you have a
db.define_table('item',
Field('number','integer'),
Field('name'),
Field('link'))
and you want to make a view with ajax sortable links like:
<ul id="sortable">
{{for i,row in enumerate(db().select
(db.item.ALL,orderby=db.item.number):}}
<li id="{{=row.id}}_item" class="sortable_item">
{{=A(row.name,_href=row.link)}}
</li>
{{pass}}
</ul>
No make them sortable you need:
1) The script below:
<script src="{{=URL
(request.application,'static','jquery.dimensions.js')}}"></script>
<script src="{{=URL(request.application,'static','ui.mouse.js')}}"></
script>
<script src="{{=URL
(request.application,'static','ui.draggable.js')}}"></script>
<script src="{{=URL
(request.application,'static','ui.droppable.js')}}"></script>
<script src="{{=URL(request.application,'static','sortable.js')}}"></
script>
<script>
function sortUpdate(a,b)
{
var dragEls = jQuery
(".sortable_item");
var els =
'';
jQuery.each(dragEls, function ()
{
var cur_id = jQuery(this).attr('id').split('_').shift
();
els += cur_id
+",";
});
var url = '{{=URL(r=request,f='sort')}}?order='
+els;
jQuery.get
(url);
}
jQuery(document).ready(function()
{
jQuery("#sortable").sortable({stop:
sortUpdate });
});
</script>
2) the following callback action:
def sort():
for i,id in enumerate(request.vars.order.split(',')[:-1]):
db(db.item.id==id).update(number=i)
return 'done'
that is all.
perhaps somebody could make a plugin about this.
On Jan 30, 8:42 pm, weheh <[email protected]> wrote:
> Re Jonathan's comment about needing sortable lists and tables, I +1
> the motion. I have done sortable table and it's nice. But what I
> really need is to re-order a sequence of things. For instance, in a
> CMS, you would upload images and content for a page and put them under
> a link. You might have multiples of these and therefore need multiple
> sub-links. The order of the sublinks could be changed by listing the
> links in a table and dragging the order. Much easier than typing a
> number into a field. I'm afraid flowplayer.org missed this one.
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.