Uncaught TypeError: Object [object Object] has no method 'charCodeAt'

Uncaught TypeError: Object [object Object] has no method 'charCodeAt'

steveocsteveoc Posts: 9Questions: 0Answers: 0
edited August 2012 in DataTables 1.9
Hi Allan,

Since the update to 1.9.3 I am receiving the following error:
Uncaught TypeError: Object [object Object] has no method 'charCodeAt' on line 3841.

I have uploaded debug info. code: ekazek

Many thanks

Steve

Replies

  • steveocsteveoc Posts: 9Questions: 0Answers: 0
    Looks like a jQuery Object (HtmlTableElement) is being passed to the function
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Oh dear - that doesn't sound good. Could you possibly link me to a test case showing the problem? I don't see anything in the debug trace (thanks for that) which would cause it.

    Thanks,
    Allan
  • CT1972CT1972 Posts: 2Questions: 0Answers: 0
    I had the same problem without this update
    I think it is because of the new jquery release
    Change the http link to latest jquery version to the 1.7.2 (download it to your local machine)
    Regards
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    I've just run the DataTables unit tests through with jQuery 1.8.0 and they all pass no problem. However, the coverage isn't perfect so there could be something slipping between the cracks.

    If someone is able to give me a test case which shows this problem, so I can reproduce it and debug it, I'll get a fix in forthwith.

    Thanks,
    Allan
  • CT1972CT1972 Posts: 2Questions: 0Answers: 0
    I don´t know if this will help you:
    Library jquery.dataTAble.js, in _fnStringToCss(s) function, the line var c = s.charCodeAt(s.length - 1);
    I debugged it with alerts and s is an object, not a string
    Regards
  • steveocsteveoc Posts: 9Questions: 0Answers: 0
    @CT1972

    Excellent. moved back to JQ1.7.2. and Hey Presto.
    Strange though - it was working!!

    many thanks

    Steve
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi Steve,

    Thanks very much for the log-in - I appreciate that. Its always really helpful to see the code in action!

    Have you moved your site back to jQuery 1.7.2 as I'm not seeing the error at the moment. However, I am seeing a warning about an undefined parameter - I think you probably just need to add `"sDefaultContent": ""` to your final column (which is currently mDataProp null and DataTables won't be finding anything for the column).

    Thanks again,
    Allan
  • steveocsteveoc Posts: 9Questions: 0Answers: 0
    Hi Allan,

    yes I did roll back to 1.7.2.

    I've added the sDefaultContent:"" and the warning has disappeared. Many thanks for that.
    Though I'm still stumped as to why these errors were now starting to occur as everything was working beautifully!

    I'll be pushing a new version of the site (with 1.7.2) in the next 24 hours.

    Once I've done this I'll move the current site to a test server with jQuery 1.8 and will let you know so you can have a look at the original error.

    Many thanks for your help.

    DataTables Rocks!

    Steve
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi Steve,

    Good to hear that helped :-). I look forward (in a funny developer way...) to seeing the error!

    Thanks,
    Allan
  • jblotusjblotus Posts: 6Questions: 0Answers: 0
    same bug here
  • jcreadyjcready Posts: 44Questions: 0Answers: 0
    Also seeing this error with jQuery 1.8. In case it helps, here's the stack trace: http://cl.ly/IfFI
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Thanks for the trace, but that looks like the minified version of DataTables, so its a little difficult to tell the path.

    If anyone can give me a link to a page that shows the issue, I'd be really grateful so I fix it.

    Allan
  • jcreadyjcready Posts: 44Questions: 0Answers: 0
    edited August 2012
    I found the solution to the problem, see here: http://www.reddit.com/r/javascript/comments/xynhg/jquery_18_released/c5r0rgw

    The problem is with jQuery UI. The solution seems to be to download jQuery UI 1.8.22.
  • szurcherszurcher Posts: 1Questions: 0Answers: 0
    Thanks jcready! I actually use google for jquery and jqueryui, specifying 1.8.22 (without downloading and replacing) fixed the problem for me. Maybe they've already updated their copy. Just specifying version 1 was giving 1.8.21 still.
  • jcreadyjcready Posts: 44Questions: 0Answers: 0
    edited August 2012
    Glad to hear, szurcher! Sounds like updating to jQuery UI 1.8.22 is the real fix.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Brilliant! Thanks for the update :-)

    Allan
  • steveocsteveoc Posts: 9Questions: 0Answers: 0
    A big thank you to all for the help and to jcready for the solution.

    Steve
  • jblotusjblotus Posts: 6Questions: 0Answers: 0
    i can confirm upgrading jquery ui to 1.8.22 fixed it for me
  • JieJie Posts: 1Questions: 0Answers: 0
    Using Jquery 1.8.3 and datatable 1.9.4, I get the same error. And datatable cannot be rendered.

    My datatable has option, "sScrollX": "100%",

    After remove this option, this error is gone, and table is rendered successfully.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read

    Post a link please.
  • styustyu Posts: 2Questions: 0Answers: 0
    edited January 2013
    For a quick fix, I have added the following to line 3878 (function _fnStringToCss( s )):
    [code]if ( typeof s == "object" ) return s;[/code]

    s contained the whole table object.
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    I'd appreciate a link to a test case if someone can post it, so if there is a bug in DataTables, I can fix it.

    Allan
  • Vic_VlVic_Vl Posts: 2Questions: 0Answers: 0
    edited March 2013
    i've got the same error.
    occurs when initialising data table, and passing to it (as data) an empty array.

    setting "sDefaultContent" property for columns don't take an effect.

    "typeof s... " - takes no effect

    unfortunatly i have no time to debug it now (hope to do it later, or just to try to do it =)) ),
    my spike is just to make it (that "s") a string (before line 3878)

    [code]s = s.toString();[/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    As before, please link to a test case so I can debug and fix this issue.

    Allan
  • Vic_VlVic_Vl Posts: 2Questions: 0Answers: 0
    edited March 2013
    just init grid with one or more invisible (with no width option specified) columns and "bAutoWidth" option for grid set to false.
    in this case: s === false (line 3862) (for me, using Chrome 25)

    from line 3862:
    [code]
    // generating width for invisible column

    function _fnStringToCss( s ) {

    // "s" is actually "false"

    if ( s === null ) { // false !== null

    return "0px";
    }

    if ( typeof s == 'number' ) { // "boolean" != 'number'

    if ( s < 0 ) {
    return "0px";
    }
    return s+"px";
    }

    /* Check if the last character is not 0-9 */
    var c = s.charCodeAt( s.length-1 ); //throw an exception
    if (c < 0x30 || c > 0x39)
    {
    return s;
    }
    return s+"px";
    }
    [/code]

    probably a better solution (depending on posts in this topic) is something like that:

    [code]
    function _fnStringToCss( s ) {

    // if s is a number
    if (typeof s == 'number') {

    if (s < 0) {

    return "0px";
    }

    return s+"px";
    }


    // if s is a string
    if (typeof s == 'string') {

    /* Check if the last character is not 0-9 */
    var c = s.charCodeAt(s.length - 1);
    if (c < 0x30 || c > 0x39) {

    return s;
    }

    return s + "px";
    }

    // on any other type - return zero width
    return "0px";
    }
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Example with `bAutoWidth: false` working as expected: http://live.datatables.net/azotev/edit#javascript,html .

    As I said, I need a test case so this can be reproduced and fixed properly, but without a way to reproduce the error I can't do that.

    Please also check you are using an update to date version of jQuery UI (again without a test case I'm guessing...).

    Allan
  • blairh01blairh01 Posts: 1Questions: 0Answers: 0
    Vic_Vl's solution worked great. Page had hidden columns and bAutoWidth: false. I went ahead and implemented his replacement code in the second listing above for the _fnStringToCSS() function and life is much better. Table renders without throwing an error now.
    My page happened to be using Chrome 26.0.1410.64 jQuery 1.9.1 jQueryUI 1.8.21
    Thanks Vic_VI
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    > jQueryUI 1.8.21

    I'd suggest updating to at least the latest 1.8 of jQuery UI.

    I really would like a test page showing this problem, so I can fix this in DataTables core. If someone, anyone!, is experiencing this problem, please link me to the page.

    Allan
  • maltemalte Posts: 1Questions: 0Answers: 0
    Hi,

    I had the same problem with datatables 1.9.4 after upgrading jquery 1.7.1 to 1.10.2.
    Sometimes the method outerWidth() in _fnScollDraw() returns not a value, but an object (the table object itself).

    var iOuterWidth = $(o.nTable).outerWidth();
    nScrollHeadTable.style.width = _fnStringToCss( iOuterWidth );

    The error than occures in _fnStringCss, because it expects a string.

    I found a bug ticket in jquery http://bugs.jquery.com/ticket/12491 which says that it is caused by a hooking outerWidth function in jquery UI.

    After upgrading jquery UI from 1.8.17 to 1.10.1 the error has been gone.

    Maybe that helps somebody.

    Malte
This discussion has been closed.