Reputation: 1902
On page load I have a table that is contained in a hidden div. The table only has header and footer definitions, but no data rows. The data rows a loaded dynamically using Ajax.
Once a user clicks on a button, the hidden div containing the table (and other static text) is shown. My problem is that the table layout does not look very nice since I am using width = 100% and at the beginning the table is hidden and hat 0 width to start out with.
Ideally I would like to know if there is a way to force a redraw of the table once the div is visible?
Upvotes: 1
Views: 1143
Reputation: 41050
You could clone()
the element, then remove() it and then insert the copied clone and show it.
You can clone(true, true)
with two parameters to rebind all events when insert again. If this does not work, there is an other way by John Reisig itself: What is the most efficient way to deep clone an object in JavaScript? This worked for me once when clone() was not enough. Use a jQuery element as "oldObject
" from the first answer.
Example:
// Deep copy
var newObject = jQuery.extend(true, {}, $('#tableToClone'));
$('#tableToClone').remove();
$('#divArroundTable').html(newObject);
Upvotes: 0
Reputation: 4295
my suggestion is to style the table with CSS. There are two strategies that I use:
Upvotes: 0
Reputation: 6586
I'm assuming you have code similar to this:
success: function (response) {
$('mytable').html(response).show();
}
Why not set the width after the show method, like this:
success: function (response) {
$('mytable').html(response).show();
$('mytable').css('width', '100%');
}
Upvotes: 1