Cannot read property 'sWidth' of undefined - Bug in jQuery Datatables Triggered by ColVis

Cannot read property 'sWidth' of undefined - Bug in jQuery Datatables Triggered by ColVis

robinwilson16robinwilson16 Posts: 1Questions: 1Answers: 0

Hello

I was just posting here to raise awareness of a bug I hit regularly when working with jQuery Datatables where it throws the error "Cannot read property 'sWidth' of undefined" which is difficult to debug as the error provided doesn't indicate what the issue actually is.

It was posted on StackOverflow in 2013 and is still present. If columns are defined in the code but the number of columns defined does not match the table header then this always triggers this error so you must go through until you locate the difference.

The issue is that jQuery Datatables attempts to read the width of a column when that column is hidden triggering the error above. If it has a case statement to check the column is visible before attempting to read the size then the issue does not occur.

Further details of the error are here:
https://stackoverflow.com/questions/20673825/error-with-jquery-datatables-and-colvis-plugin-cannot-read-property-swidth-of

Please could some priority be given to fix this annoying issue?

Thanks
Robin

Answers

  • allanallan Posts: 54,881Questions: 1Answers: 8,601 Site admin

    Yup - happy to fix this, but please link to a test case showing the issue. This issue normally comes from having a different number of columns in the HTML from that configured in the Javascript, but we'd need a test case showing the issue to help further since this error doesn't happen in the examples.

    Allan

  • KanthKanth Posts: 20Questions: 9Answers: 0
    edited May 2020

    Any way to trap this error and say somehing like "Check that your HTML columns match your data columns"?

  • allanallan Posts: 54,881Questions: 1Answers: 8,601 Site admin

    Yes - we need to improve our error messaging with this error - possibly with sanity checking code when the table is initialised.

    Allan

  • colincolin Posts: 12,877Questions: 0Answers: 2,198

    I've raised it internally (DD-1480 for my reference) and we'll report back here when there's an update.

    Cheers,

    Colin

  • ghendricghendric Posts: 12Questions: 4Answers: 0

    Any updates on this bug? it appears to still be there..

    Thanks

  • colincolin Posts: 12,877Questions: 0Answers: 2,198

    No, no updates, I'm afraid.

    Colin

  • sakshimorya90sakshimorya90 Posts: 11Questions: 1Answers: 0

    Hello Any update for this.
    Because in local it's working fine, but at time to deployment we still face this issue.

  • colincolin Posts: 12,877Questions: 0Answers: 2,198

    No, it's still in the backlog. If you're seeing it in deployment, it would suggest the data you're getting from the server, or the table initialisation is different to your local environment. The fix we would implement would be more graceful error handling, such as a more useful error message, but the misconfiguration would still exist.

    If you can link to your page we can take a look,

    Colin

Sign In or Register to comment.