nluigi nluigi - 4 years ago 221
jQuery Question

Javascript simulate a small window resize event

Let me preface this by saying the answer to my question is most likely not the most ideal solution to my problem but it seems to me to be the fastest solution. At a later stage i may revisit this issue and properly solve it.

I have a Datatable with the YADFC plugin which is behaving weirdly.

On refresh of the page, the headers are misaligned wrt the columns as below:

enter image description here

If i resize my window even by the smallest amount, the headers are recalculated and snap in the correct position as below:

enter image description here

Is there any way to programmatically trigger a small window resize event?

Update: Solved using

$(window).trigger('resize');

Answer Source

try this

    $(window).resize(function() {
        setTimeout(function() {
            resize();
        })
    })
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download