I have a complex page of data and want to sort various columns of the
db so... the way I am trying to do it is
with jquery but I don't know how I can get the variable returned by
the jquery function into my template
maybe I should be using custom template tage for this?

Here is a very stripped down version
In my html file
 <script type="text/javascript">
   function sort_col(col_name,seq_name)
   {   $.postJSON("/jobs/sequence/sort_shots",
{seq:seq_name,col:col_name},
       function (json)
       {
          {{shot_list}}=json['shot_list']; // this dosn't work but it
is what I would like to do
       }
   }
 </script>

 {% for f in shot_fields %}
   <td onclick='sort_col("{{f}} {{a.name}}")'> {{f}}
      <ol>
        {% for s in shot_list %}
        <li> {{s|lookup:f}} </li> <!-- where lookup is constructing a
string like a.name etc -->
        {% endfor %}
      </ol>
 {% endfor %}

Here is the view function in views.py

# ajax request for sorting of database rows
def sort_shots(request):
    result={'shot_list': []}
    if request.method =="POST":
        try:
            seq=request.POST["seq"]
            col=request.POST["col"]
        except KeyError:
            json=simplejson.dumps(result)
            return HttpResponse(json,mimetype='application/json')

        s=list(Shot.objects.filter(sequence__name=seq)).order_by(col)
        result={'shot_list':s}
        if len(s)==0:
            json=simplejson.dumps(result)
        else:
           json=simplejson.dumps(result)
        return HttpResponse(json,mimetype='application/json')

I don't want to just reload the page because it has quite a lot of
state that would be lost
Thanks for any help

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to