Custom order of options in a dropdown filter

Custom order of options in a dropdown filter

MichaelGibbsMichaelGibbs Posts: 10Questions: 3Answers: 0

http://live.datatables.net/nucojuha/1/edit

Hi, I'm brand new starting with datatables. I found that you can have dropdowns but the options are always sorted for each column. What I would like to happen is that I am able to have the options of any column in any order I want. Preferably me Hard Coding the options and that they still work in selecting for that column. Is that something that can be done? Thank you.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,295Questions: 26Answers: 4,768

    This code, in your example, sorts and builds the select options:

                  column.data().unique().each( function ( d, j ) {
                        select.append( '<option value="'+d+'">'+d+'</option>' );
                    } );
    
    

    You can replace it and build the options list in any order you like.

    Kevin

  • MichaelGibbsMichaelGibbs Posts: 10Questions: 3Answers: 0

    Hi , thanks for your help. May I ask how you would go about doing that?

  • kthorngrenkthorngren Posts: 20,295Questions: 26Answers: 4,768
    Answer ✓

    This example show one way to manually determine the order. The Office column is manual, the others are sorted.
    http://live.datatables.net/nucojuha/4/edit

    Note that 'Tokyo' is in the list of values for the desired select list order. But since its not found in the data its not placed in the select list.

    Kevin

  • MichaelGibbsMichaelGibbs Posts: 10Questions: 3Answers: 0

    You're a legend. Thank you so so much for your help :smile:

This discussion has been closed.