1

I am using django tables2 to generate my tables dynamically. I display a table using a custom format. Now on clicking a button in a table I need to update the data in the table to something else without refreshing the whole page. Is it possible that I send in an updated "table" variable from the server side and and just parse through the whole table again with that variable instead of picking up each and every element by hand using queries and then replacing the data inside them.

My code is like this:

{% block table %}
<!--table parsing done here -->
{% endblock %}

I found similar question at this link but there was no answer:

Rendering JSON objects using a Django template after an Ajax call

1 Answer 1

1

Do you have an id on the table? if so you do something like this:

$("table[id]").each(function(i,item){
  var $table = $(item)
  var table_id = $table.attr('id')
  $table.find(".refresh-button").on("click", function() {
    $table.load(location.href + " " + table_id);
  })
})

This uses jquery to reload the page in an ajax call, and then swap the refreshed table into the document where the old data used to be.

ALTERNATELY:

you can define a new url, that just returns the rendered table, and call this in the inner function.

$table.load("/_tables/my_table/ " + table_id);
Sign up to request clarification or add additional context in comments.

1 Comment

Hey @SilentPro, If this answer helped or informed you, would you consider marking as correct?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.