Buttons Error (Uncaught TypeError: str.replace is not a function)

Buttons Error (Uncaught TypeError: str.replace is not a function)

SeannSeann Posts: 6Questions: 0Answers: 0

Hi Allan,

Really looking forward to this release. .I am getting an error in chrome when I click on any of the buttons.

Uncaught TypeError: str.replace is not a function or 'a.replace is not a function' if using the minified version

datatables.js : 92018

if ( config.stripHtml ) {
        str = str.replace( /<.*?>/g, '' );
    }

Replies

  • jouvenjouven Posts: 22Questions: 1Answers: 0

    I have the same problem, debugging with firebug it seems to str.replace when str is number object... using: //cdn.datatables.net/buttons/1.0.0/js/dataTables.buttons.js

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    Thanks! I'll get a commit in for this shortly.

    Allan

  • DanTheManDanTheMan Posts: 5Questions: 0Answers: 0

    I just updated from the download builder, I have exactly the same problem.

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    Hi,

    I've committed the required fix, but the download builder will use the release version rather than latest check in. I'm going to make a release of Buttons 1.0.1 with this fix, and others, at the end of the week. Until then you can either include the fixed file locally or patch your local version.

    Allan

  • DanTheManDanTheMan Posts: 5Questions: 0Answers: 0

    Thanks for the very fast reply!!
    I just tried the CDN and all I'm getting for datatables.min.js is Error: Build is incomplete
    Anyway, great work the improvements look very exciting

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    Embarrassing code mistake in code that no one will ever see ;-). It is fixed now and you shouldn't see that error now!

    Thanks,
    Allan

  • DanTheManDanTheMan Posts: 5Questions: 0Answers: 0

    Works beautifully.
    Thank you again Allan.
    I'm very happy that my switched-on users can say goodbye to flash!

  • N4M3ZN4M3Z Posts: 2Questions: 1Answers: 0
    edited August 2015

    I believe the correct code should be, since server-side processing is not strictly required to return strings, but your export code requires it:

    if ( typeof str !== 'string' ) {
        return String(str);
    }
    

    If possible, consider also including this for stripHtml:

    str = str.replace( /&nbsp;/g, ' ' );
    str = str.replace( /&#8209;/g, '-' );
    
  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    That is the fix - although I didn't cast it to be a string as I didn't think that was needed.

    Converting HTML entities sounds like a good idea. I wonder if it can be generalised. I'll look into that.

    Allan

  • rblancorblanco Posts: 1Questions: 0Answers: 0

    Hi allan, i had the same error with the latest versión 1.10.9, the only way that worked for me was with the cast that N4M3Z said,

    return String(str);

    thanks,

This discussion has been closed.