ASP.Net Update Panel + postback + window resize == datatables.js error (solved)

ASP.Net Update Panel + postback + window resize == datatables.js error (solved)

lw22xlw22x Posts: 1Questions: 0Answers: 0

First off, I want to say how grateful I am to be able to use this wonderful DataTables product - it is absolutely fantastic!

I've been working on this problem for days now. If my table is on an ASP.Net Update Panel and I set off an event that issues a postback, I get the error: Unable to get property 'style' of undefined or null reference. After finally discovering that someone else had the same problem in this post here: https://www.datatables.net/forums/discussion/27836/manual-updates-applied-to-jquery-datatables-js, I was able to find the issue in the _fnCalculateColumnWidths and _fnScrollDraw functions.

The line:

headerCells[i].style.width = column.sWidthOrig !== null && column.sWidthOrig !== ''String ? _fnStringToCss( column.sWidthOrig ) : '';

in the _fnCalculateColumnWidths function is what initially breaks, and that's because headerCells is a 0-length array but the code assumes that there will always be > 0 header cells as long as visibleColumns.length > 0. For some reason, probably because of the Update Panel and the asynchronous nature of the page's rendering, the tmpTable clone of the actual table doesn't have any header cells at the time that the code is run.

I was able to code around this by using PLC's solution in the https://www.datatables.net/forums/discussion/27836/manual-updates-applied-to-jquery-datatables-js post (only where he references line 4168), but since this post from May last year there has been a number of changes to datatables.js so I had to add about 6-7 checks for empty arrays and elements. Once I added these checks, the grid works perfectly again. I can re-size the grid, sort, use the buttons, search, do anything else - it works as intended.

I wanted to share this since I've been having so much trouble getting the Update Panel and DataTables to work together, and I thought it would be good to know that PLC isn't the only user out there that was having this issue. If anyone wants a detailed breakdown of the changes that I made, just let me know.

Replies

  • ortoorto Posts: 1Questions: 0Answers: 0

    I have been struggling with the exact same thing, so if you could please send me or post the details I would be so grateful.

This discussion has been closed.