S
S
ScroogeM2017-02-09 12:06:38
Django
ScroogeM, 2017-02-09 12:06:38

How to dynamically update data in Django + ajax table?

There is a table:

<table class="table table-striped" id="tables">
{% for field in response %}
    <tr>

    <td>{{ field.value }}</td>
    <td>{{ field.date }}</td>       
        <td><input name="checkd"  type="button" value="Подтвердить" class="btn btn-success"
                   data-trans-id="{{ field.id }}" data-url="{% url "dashboard:change_valid" %}"
        data-valid="False"/></td>

        <td><input name="delete" type="button" value="Удалить" class="btn btn-danger"
                   data-trans-id="{{ field.id }}" data-url="{% url "dashboard:delete" %}"
        /></td>
    </tr>
{% endfor %}

it is necessary that after confirmation/deletion the line was deleted from the table without refreshing the page.

I found on the Internet that you can load data like this after an ajax request:
function(data){
$('#tables').html(data) 
}


As far as I understand, it is necessary to form a ready-made html table with all the data in the view, but I did not find how to do it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2017-02-09
@sim3x

You check
request.is_ajax()
and send only the table instead of the whole page

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question