input fields breack sorting

input fields breack sorting

borisavborisav Posts: 5Questions: 0Answers: 0
edited October 2009 in General
Hi All,
First thanks Allan for your great plug-in!!!!

I'm hoping that I'm not the only one with this issue.

I have a table that is a mix of output fields (text with value) and input fields (form element with value) which is causing sorting to not work correctly. Right now sorting is working first for all output fields and then input fields. Sorting them separately from each other when it should be together.

Example:

BBB

Replies

  • allanallan Posts: 61,663Questions: 1Answers: 10,095 Site admin
    Hi borisav,

    The reason the sorting here doesn't work is that it is using the HTML to sort by as well (since it's treating it as just a string). This isn't what you want. So you could use the 'html' type which is built into DataTables - but that will strip all HTML (including the value="") which I don't think is what you want either. So... What you'll need to do is have a custom plug-n sorting function:

    Development documentation: http://datatables.net/development/sorting
    Examples: http://datatables.net/plug-ins/sorting

    So what you would need to do is to check for the "" element, and if it is there, use the value - if it's not then use the string raw.

    However, you should be aware that the 'value' attribute of the input element will not change with a user's input. Therefore if I was to change your 'ZZZ' input to 'AAA', it would still sort as if it was 'ZZZ'. If you want to overcome this, you would need to query the DOM on each ordering query which is quite an expensive operation. It could be optimised, but a little tricky if you want to have this feature.

    Hope this helps,
    Allan
  • borisavborisav Posts: 5Questions: 0Answers: 0
    Hi Allan,
    Thank you for the link. I'm going to forward the link to the developer I'm working with on this. I'm hoping this will be a good start for us to figure it out. :-)
This discussion has been closed.