Sorting issue when having html contents inside TD

Sorting issue when having html contents inside TD

gowrishgowrish Posts: 12Questions: 0Answers: 0
edited April 2014 in General
Hi,
I'm having numeric content wrapped with Html and placed inside the TD.i want to sort column asc or desc.Since it is wrapped with html, i've used Numeric HTML type detection plugin and sorting plugin then initialized aoColumns
with sType:"num-html" but still i can't resolve this issue.

Any Help?

Here is the debug data for my table http://debug.datatables.net/eyofop

Replies

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Try using DataTables 1.10 which should sort that type of data, numerically, automatically. http://next.datatables.net/download .

    If it doesn't work, please link to a test case.

    Allan
  • gowrishgowrish Posts: 12Questions: 0Answers: 0
    Hi allan,

    Tried with dataTables 1.10 but still the same.
    here is the link to JsFiddle

    http://jsfiddle.net/68vhp/1/

    Fullscreen result: http://jsfiddle.net/68vhp/1/embedded/result/

    Thanks,
    Gowrish.
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    If you just remove the sType set (which isn't needed in 1.10) it does sort correctly: http://jsfiddle.net/68vhp/2/ . Hooray for progress! :-)

    Allan
  • gowrishgowrish Posts: 12Questions: 0Answers: 0
    Hi allan,

    No,i think it's still not sorted correctly.

    after sorting AS2000 column descending the values should be

    61.0
    27.0
    23.5
    23.40
    15.0

    but it's getting sorted as

    27.0
    23.5
    23.40
    61.0
    15.0

    Thanks,
    Gowrish.
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Your first list is the exact ordering that I'm seeing when using the updated fiddle I linked to. What browser are you using?

    Allan
  • gowrishgowrish Posts: 12Questions: 0Answers: 0
    Is it? tried sorting that AS2000 column? i'm using chrome Version 34.0.1847.116 m .tested in chrome and firefox still the same allan.

    Gowrish.
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    > Is it?

    Yes. Screenshot from Chrome using the fiddle I linked to: http://datatables.net/dev/gowrish.png

    Allan
  • gowrishgowrish Posts: 12Questions: 0Answers: 0
    Hi allan,

    i've tested in another machine running with windows xp,Yes it works correctly as like your screen shot.but it's not working correctly in my windows7 machine..

    here is the screen shot of my machine https://drive.google.com/file/d/0B3IRPs7dec7zdEFiaGZKTDlndzQ/edit?usp=sharing
  • gowrishgowrish Posts: 12Questions: 0Answers: 0
    Hi Allan,

    It seems to be a browser issue. In Windows XP machine, version 31.X of chrome used when i updated to version 34.X it produce the same issue.

    Gowrish.
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    I'm using Chrome 33 Mac, Safari and Firefox and they all appear to work as expected.

    I would need a way to be able to reproduce the error to be able to fix it.

    Allan
  • gowrishgowrish Posts: 12Questions: 0Answers: 0
    cant we find why this happening with the help of debug data?
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Not really since it is working in the cases that I can see. I would need to be able to reproduce the error so I can debug it, understand what is going wrong and ensure that it is fixed.

    Allan
  • gowrishgowrish Posts: 12Questions: 0Answers: 0
    Hi Allan,

    Table was constructed in this way http://stackoverflow.com/questions/23126952/column-sorting-issue-in-datatables (posted by my friend)
    this way of constructing causing issue?

    Gowrish.
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Not that I can see. Looks like a straightforward table.

    Allan
  • MikeSMikeS Posts: 113Questions: 1Answers: 0
    FWIW, I'm seeing the same strange sorting behaviour that gowrish is in allan's fiddle. My Chrome version is Version 34.0.1847.116 m and I'm on Windows 7 Pro. Looks to be a Chrome issue?

    I tried the same fiddle in IE10 and can't determine anything cause it crashes with a Webpage Error "Line: 1513 Error: Access is denied."
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Aye - I'm seeing it in the dev version of Chrome as well... Debugging time...
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Appears not to be a DataTables error, but a Chrome bug. I've opened an issue here: https://code.google.com/p/chromium/issues/detail?id=365713 . It might get more attention the more people that star it... :-)

    Allan
  • gowrishgowrish Posts: 12Questions: 0Answers: 0
    Hi Allan,

    Thanks for your continued support.i think the issue appears to be happen in firefox version 28.0 as well.

    Gowrish.
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Agreed - I've added a comment to the bug. That might be bad news - possibly a spec somewhere has been updated.

    This might be the Firefox bug that they "fixed": https://bugzilla.mozilla.org/show_bug.cgi?id=392511 .

    I think your fix is going to be to not use entities in your attributes. I don't really see how DataTables can workaround that.

    Allan
  • gowrishgowrish Posts: 12Questions: 0Answers: 0
    since i don't know much in-depth how browser handles code internally,i could not able to help anything in finding what went wrong.just hopping it ill be fixed. :-)
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Me too! Interested to see what feedback the Chrome folks give.

    Allan
  • gowrishgowrish Posts: 12Questions: 0Answers: 0
    Allan,got reply from chrome guys,did you see that?
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Yeah - I need to look at it in detail which I will do later today.

    Allan
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    edited April 2014
    So the issue is in how DataTables strips HTML. It uses a relatively simple regular expression: `/<.*?>/g` - i.e. select anything between `<` and `>` , and as small as possible. It removes it.

    Because we how have extra `<` and `>` characters in the string, this falls apart.

    I think the solution here is that we need a plug-in sorting function that will cope with this type of nested HTML. I could put it into DataTables core and there are two options:

    1. Use the browser to do it - i.e. write the innerHTML into a node and then read it back using `textContent`

    2. Write a parser.

    Option 1 is _horribly_ slow. Fine for a couple of strings, but if you have a large table and need to do it for every cell. So not an option. Option 2 would require a significant amount of code, and I'm already past the size I wanted v1.10 to be.

    So I think that the core will stay as it is, and we need a plug-in for anyone that does want to have nested HTML in attributes.

    Allan
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    There is one more option - use `data-` attributes in DataTables 1.10 to give the numeric data for sorting. This, I would say, is my preferred way of doing it.

    Allan
  • gowrishgowrish Posts: 12Questions: 0Answers: 0
    edited April 2014
    Hi Allan,

    Can u give me a example of how to use [data-] attribute? this one seems a quick fix.

    Thanks.
  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    http://next.datatables.net/examples/advanced_init/html5-data-attributes.html
This discussion has been closed.