Supose I have a view that receive a list of things like that:
@(notices: Seq[Notice])
@for( not <- notices) {
<tr> not.title </tr>
}
....
and I have a method in a controller that its call by ajax and changes the values of the list. I know that de method can return a Result and re-render the page with the new values, like:
public Result editNotice() {
/*change the list */
return ok(list.render(notices);
}
But I want to refresh only the table where the list is.
How can refresh the list in the view without reload the entire page?
Finally I resolved this returning the Result from the controller, but replacing the content in the html with javascript and a div.
Controller:
public Result editNotice() {
return ok(table.render(notices);
}
Html: list.scala.html
@()
<div id="table">
</div>
<li>
<a class="ajax-call" href="#table" onclick="$('#table').load('/editNotice';"/>
</li>
Html: table.scala.html
@(notices: Seq[Notice])
<table>
@for(not <- notices) {
<tr><td>@not.title</td></tr>
}
</table>