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>
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
A example view
inside of
search_results.htmlyou will just render the results into your table