sData .charAt Error

sData .charAt Error

hozthozt Posts: 45Questions: 0Answers: 0
edited May 2012 in General
I accept all suggestions, but this is mostly directed to allan, which I hope allan you can help me out.

I've read about the errors surrounding this type detection\sorting plugin, for per instance 'currency' detection.

You said in a thread (I've lost track) that it happens when DataTables it's trying to "work" on something that it's not a string.
You also said that you've came across this a few times and you tried to fix it, well, what happens here is, I was implementing a custom currency type detection with success, then I have two fields that came from the DB (two integers), which I don't treat at all, so they are handled such as:

"field" : 134,

And I get -> sData.charAt is not a function
If I for instance (in PHP) $field = "". $field;

I get this in the aaData
"field" : "134",

And problem solved, but I have lots of tables I want to implement my custom currency, and I don't want to this "weird" trick to make my int's- string's, so DataTables doesn't trip out on me.

Replies

  • hozthozt Posts: 45Questions: 0Answers: 0
    The thing to notice here is, that the error column (the int) wasn't even the field i typed for the currency (with sType) neither it fit the expression matching for finding my " EUR" in the end of the string.
  • allanallan Posts: 62,211Questions: 1Answers: 10,206 Site admin
    DataTables core shouldn't have any problem with non-string data. It used to, in the dark old days, but that was long ago - possibly you found a forum thread from that time? Anyway - it should work fine now. If you do run across a case where it doesn't , please post a link to a test case so I can take a look at, and fix, the problem.

    Allan
  • hozthozt Posts: 45Questions: 0Answers: 0
    Yes, once again I can only show it to you if I happen to give you a test password in PM, if you can. Since this project is now production, I just need a little bit of time, to set up a demo database.

    Also allan, I can't run debugger on the page, obviously, if I let the error happen. But want me to run it without the error, so you can look at the sAjaxSource JSON and see if why if I let it come as an int, it crashes?

    Thanks.
  • allanallan Posts: 62,211Questions: 1Answers: 10,206 Site admin
    I suspect that it is probably a combination of factors, so I'd probably need to see the full page with its error. So yes, a PM whenever you have it ready would be great if you have time to set that up :-).

    Thanks,
    Allan
  • hozthozt Posts: 45Questions: 0Answers: 0
    Once you can mate look up at the PMs with the test page.

    I might be looking at the "Orthogonal data" post you made, this was hard to find, but it seems it may even be a better option, to use a currency example you have there for better filtering, sorting, then the type detection thing, since I added the EUR manually.
  • allanallan Posts: 62,211Questions: 1Answers: 10,206 Site admin
    Thanks for the PM. I think the problem you are enchanting is not in DataTables core, but rather with the currency type detection plug-in, which is where the error is occurring. It isn't coping with non-numeric data.

    I'd just add something like:

    [code]
    if ( typeof sData !== 'string' ) {
    return null;
    }
    [/code]

    at the top of that plug-in function.

    Allan
  • hozthozt Posts: 45Questions: 0Answers: 0
    I dunno what happened to my comment, and it was big.

    Mainly saying you should consider adding that to your function example, since it's suppose to work on strings (currency) and it doesn't have that verification.

    I for one, thought it was the core, didn't look at it correctly.

    Sorry, and thank you. !
  • allanallan Posts: 62,211Questions: 1Answers: 10,206 Site admin
    I'm currently working on getting all of the plug-ins into Git ( https://github.com/DataTables/Plugins ) and I've just committed that change. The plug-ins pages will soon be generated from that Git repo, so these improvements will be reflected on the page, and also forking / pulling / pushing exec will be easier for everyone to update plug-ins :-)

    Allan
This discussion has been closed.