[Answer]-Update table html in django

1👍

Here, <td {{ column.attrs.td.as_html }}>{{ cell }}</td> is where data is being used for displaying data. If you want to do a ajax request here, you have to do it in cell section. For example:

{% for column, cell in row.items %}
{% if column|stringformat:"s" == "some-string" %}

<td {{ column.attrs.td.as_html }} class="ajax-request">{{ cell }}</td>

<!-- or you can use:
<td {{ column.attrs.td.as_html }}><input class="ajax-request" value={{ cell }} type="button (or any other type)"></td>

for choice field, you need to render like 
<td {{ column.attrs.td.as_html }}><select id=".ajax-request">
{% for items in cell.values %}
<option value={{ items }}></option>
</select></td>
-->

{% else %}
<td {{ column.attrs.td.as_html }} class="ajax-request">{{ cell }}</td>
{% endif %}
{% endfor %}

<script>
$(document).ready(function(){

 $('.ajax-request').change(function(){
    var e = document.getElementById("select_dropdown");
    var value = e.options[e.selectedIndex].value;
    $.ajax({
        url: "your-url",
        type: "post", // or "get"
        data: value,
        success: function(data) {
          alert(data.result);
        }});

});
</script>
👤ruddra

Leave a comment