sSortDataType cannot sort when value='default'

sSortDataType cannot sort when value='default'

nicsoftnicsoft Posts: 37Questions: 0Answers: 0
edited February 2012 in DataTables 1.8
I am trying to sort a column with select elements. I have defined {"sSortDataType": "dom-select"} for that column.

I have two other columns that has select elements and is defined in the same way, for those it works without problem.

For each row in the select column that doesn't sort, I have value='default' for one option in each select element. After some testing I believe (tho not 100% confirmed yet) that the problem is due to the fact that I do have value='default' in my elements.

Can someone confirm that it is incorrect to set value='default', or is it supposed to work?

Replies

  • nicsoftnicsoft Posts: 37Questions: 0Answers: 0
    It's confirmed, removing any value='default' makes the sort works as expected. Still, I couldn't find any information that it shouldn't be possible to use values='default'. Is this generally known?
  • allanallan Posts: 61,830Questions: 1Answers: 10,132 Site admin
    I don't quite understand I'm afraid - sorting is breaking if you have value="default" in the select? I don't really see why the sort would care what the value of the select element is - it just takes a string value and sorts that.

    > For each row in the select column that doesn't sort

    All rows in DataTables must be sortable of the column is. The row position cannot be fixed. A column can be disabled from allowing sorting on it, but if it is sorted, then all information in that column will be sorted upon, moving rows as needed.

    Perhaps you can link us to your page please?

    Allan
  • nicsoftnicsoft Posts: 37Questions: 0Answers: 0
    Ok, I was a bit unclear. It sorts but not according to the value of the selected element.

    The only thing I know is that I used different kind of values (some kind of ID) instead of default value of the selected option and then it worked. Unfortunately, I cannot share a link just yet, it's under development and the goal environment isn't up'n running yet (i.e. I have nowhere to put it...). But the cell looked like this when not sorting correctly:

    [code]


    Karoline Ingmarsson (karin)
    Karin Andersson (kaand)
    Anders And (stig)
    -

    [/code]

    Of course, sometimes when one has a problem, one do some things to fix it and it starts to work. The actual reason why it started to work again could have been any other reasons, e.g. a missing ' came to place without thinking about it (but I checked carefully...). However, I only remember changing the value to something else but 'default'.

    Niklas
  • nicsoftnicsoft Posts: 37Questions: 0Answers: 0
    I did try to recreate the problem now but couldn't, so it's a bit difficult to provide more information. However, it's solved so I'm happy.
  • nicsoftnicsoft Posts: 37Questions: 0Answers: 0
    And now, after changing back, I did notice one difference (double checked). When having the 'default' value the sorting was like this (for select elements where there is no initial selected options (i.e. no values set in database) I have '-' as default option):

    D
    C
    B
    A
    -
    -
    -

    But when changing back and having some kind of id as value, the sorting is like this:

    A
    B
    C
    D
    -
    -
    -

    I'm still happy because it sorts as I want. But I do feel like value='default' does something at least. Is the sorting utilizing the 'value' in some way? When having value='default' for one option, I do mix types since the rest of the options are having som kind of INT as value.
  • allanallan Posts: 61,830Questions: 1Answers: 10,132 Site admin
    Good to hear you are happy with it now :-)

    Basically what should be happening is that DataTables will take the currently selected value (regardless of if it is "default" or anything else) and then sort it with all the other selected values.

    Allan
This discussion has been closed.