1

I have a DataTable.

When I set it, I get no errors, the table is properly generated, but then whenever I resize the window, I'm getting this error:

0x800a138f - JavaScript runtime error: Unable to get property 'style' of undefined or null reference

I don't think I can reproduce the code here, but I can guarantee that the table structure is correct.

This is what I'm using to create the DataTable:

function initDataTable() {
    if ($.fn.dataTable.isDataTable($('#grdPrincipal'))) {
        $('#grdPrincipal').DataTable().destroy();
        initDataTable();
    } else {
        $("#grdPrincipal")
            .DataTable({
                scrollY: 210,
                scrollX: true,
                fixedHeader: true,
                fixedColumns: true,
                paging: false,
                info: false,
                searching: false
            });
    }
}

Since I'm using a UpdatePanel in my asp.net webforms project, I have to run this code whenever I do a postback, because the table is rebuilt every time.

There are no problems with postbacks or anything, as I said, the only problem is when I resize the window.

What could it be?

1 Answer 1

1

Try destroying the datatable before you update your updatePanel, like this:

var prm = Sys.WebForms.PageRequestManager.getInstance();
    function BeginRequestHandler(sender, args) {
        //Runs before updatePanel starts updating
        $('#grdPrincipal').DataTable().destroy();
    }

    function EndRequestHandler(sender, args) {
        initDataTable();
        //Runs after updatePanel has finished updating
    }
    prm.add_beginRequest(BeginRequestHandler);
    prm.add_endRequest(EndRequestHandler);
Sign up to request clarification or add additional context in comments.

11 Comments

I have done something different here and I have noticed that the first time the dataTable is created, I can resize the window as I wish, but after the updatePanel is reloaded, this error is thrown if I resize the window. When the updatePanel is reloaded, the table is rebuilt so it's not a datatable anymore.
I have this -> function pageLoad() { initDataTable(); }
Hmm looks like you need another event callback.. the ".resize()" jQuery's feature. I'm writing it in my post, take a look in 1 minute.
Take a look now, hope it helps
This actually kind of ruined my table. It's duplicating the rows.
|

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.