Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9261529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:10:03+00:00 2026-06-18T13:10:03+00:00

I am stuck with this problem: I have a search result page in which

  • 0

I am stuck with this problem: I have a search result page in which there are several results. I want the user to be able to sort the results depending on some criteria. I am doing this in AJAX. The problem is how to render the sorted data coming from the server to fields again.

function sort(){
    var sortid = $('#sort').val();
    $.ajax({
        type: "POST",
        url: "/sort/",
        data: { sortid: sortid },
    }).done(function(data){
        // how to render this sorted 'data' back to <td>s?  
    });
}

this is my binding code:

<select onchange="sort()" id="sort">   
    <option>price</option>
    <option>rate</option>
</select>

this is the result place:

<tr class="result">
    <td>
        <li>{{loc.locationname}}</li>
    </td>
    <td>    
        <li>{{loc.rating}}</li>
    </td>
    <td>
        <li>{{loc.price}}</li>
    </td>
</tr>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T13:10:03+00:00Added an answer on June 18, 2026 at 1:10 pm

    Your view can return a rendered snippet like which you can just render into a div on the client side

    Your ajax call can look like this

    function sort(){
        var sortid = $('#sort').val();
        $.ajax({
            type: "POST",
            url: "/sort/",
            data: { sortid: sortid },
        }).done(function(data){
             $('#results-div').html(data.html);
        });
    }
    

    A example view

    import json
    from django.shortcuts import HttpResponse
    from django.template import loader, RequestContext
    
    
    def my_view(request, query=None):
        # trivialized example
    
        sortid = request.REQUEST.get('sortid')
    
        # you might want to store the results into cache 
        results = MyModel.objects.filter(name__icontains=query).order_by(sortid)
    
        if request.is_ajax():
           t = loader.get_template('search_results.html')
           html = t.render(RequestContext({'results': results))
           return HttpResponse(json.dumps({'html': html}))
        # handle the other cases here 
    

    inside of search_results.html you will just render the results into your table

    {% for loc in results %}
    <tr class="result">
        <td>
            <li>{{loc.locationname}}</li>
        </td>
        <td>    
            <li>{{loc.rating}}</li>
        </td>
        <td>
            <li>{{loc.price}}</li>
        </td>
    </tr>
    {% endfor %} 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hope to get solution to this problem. I have been stuck on it since
I am stuck at a small problem. I have this button within a form
I have been stuck on this problem for the whole day! Basically, I have
I have a PHP results page which starts off first-pass with ALL rows returned.
I have been stuck on this problem for days and am about the crack...
This is a common problem in ASP MVC. I have a simple search form
I have a page which contains some search fields to query a database, and
I have this problem, see the trace stack: E/AndroidRuntime(2410): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML
Hi i got stuck with this problem, i can't find out how to get
So I'm stuck on this problem where I've been asked to write an function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.