I'm trying to get a wait gif to display while my datatables are loading. I'm simply calling $(element).show()
just prior to entering my $(element).each()
loop that displays all child grids (ie. DisplayInnerTable()
) using datatables.
It seems I've narrowed the problem down to the .each()
method. If I remove all the code inside the .each()
the wait gif still won't display, and yes, i remove the .hide()
also. If I put a break point just before the .each()
the wait gif displays. Seems to be a timing issue, like the .each()
is happening so fast the wait.gif
inside the div
does not have time to render. And while on that note, why would Javascript thread prevent html element manipulation?
I did find some similar articles, but none of them answer this specific issue. Most of the other articles recommend using setTimeout()
. well I tried that in every way possible, no luck. Any help, hints or clues will be much appreciated.
Here's my code snippets:
$(document).ready(function ()
{
$('#expand-all').on('click', function () {
$("#loader-wait-ani").show();
ExpandAllChildGrids();
});
function ExpandAllChildGrids()
{
var tr;
$('#result-table tbody tr').each(function (value, index) {
tr = $(this).closest('tr');
var row = outerTable.row(tr);
userId = row.cell(tr, 1).data();
DisplayInnerTable(userId, row, tr);
});
$('#expand-all-img').attr('src', '/Images/minus.gif');
$("#loader-wait-ani").hide();
}
});
Here's my html:
<div style="width:100%; margin: 0 auto; text-align:center;">
<div id="loader-wait-ani" class="modal" style="display: none; z-index: 300;">
<img src="~/Images/waitbar.gif" alt="Pleae Wait..." width="250" height="20" />
</div>
</div>