How to sort a dynamically created table (by ajax)?
WeaponsTheyFear opened this issue · 2 comments
I love the plugin so far, but have run into an issue that I haven't been able to solve. I load content pages and they are sortable as expected. I have some fields that let me sort my pages by id, title, etc and a few more for descending/ascending and items per page. When I use these to sort, ajax call replaces the html of the old table with data for a new one (shares the same id). I've tried re-calling on success .stupidtable() but it doesn't seem to be doing anything.
Is there a proper way to re-initialize or tell stupid table what to sort after ajax basically replaces a table?
Hello there!
Thank you for the kind words. As for your issue, I believe the will_manually_build_table
setting should cover your use case.
https://github.com/joequery/Stupid-Table-Plugin#will_manually_build_table
Thanks! I may have jumped the gun, it seems the fault was my handling of ajax (using jQuery). I was re-calling stupidtable() in the success function, which has a delayed fadein of my table. I'm guessing the data wasn't fully there yet. I added a new stupidtable() call to the jquery complete function and it worked. In case anyone needs it:
$.ajax({
type: "POST",
url: "admin/content/getContentByParentId",
async: true,
data: { limit: limit, direction: direction, parent_id: parent_id, sort: sort },
dataType: "html",
success : function(html) {
$('#content_table').hide();
$('#content_table_loading').fadeOut();
$('#content_table').html(html).fadeIn('slow'); //Had a delay(500) here that's now removed
},
complete: function() {
$('#sortable_table').stupidtable();
//$('#sortable_table').stupidtable_build(); <!-- Didnt need this for it to work
},
error: function() {
$('#content_table_error').fadeIn('slow');
}
});
return false;