Individual column searching (select inputs) sort order

Individual column searching (select inputs) sort order

GrayLeaf1GrayLeaf1 Posts: 6Questions: 3Answers: 0

Hi,
When selecting the drop-down menu select menu, the items listed within the menu are sorted case sensitive like this:

A
B
C
a
b
c

How can the items in the drop-down menu be sorted:

A
a
B
b
C
c

(see the capture taken from http://live.datatables.net/gejojiqu/99/edit)

In the attachment, how can the drop-down menu items be sorted as follows:

Edinburgh
edinburgh
London
New York
San Francisco

Thanks,
John

This question has an accepted answers - jump to answer

Answers

  • jvretamerojvretamero Posts: 26Questions: 0Answers: 3

    The Individual column searching example uses the sort() method, and fortunately this method accepts a custom comparison function as parameter. You can create your own comparison algorithm to achieve what you want.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Yes, exactly what @jvretamero says! You would use a custom sorting function that just coverts everything to lowercase so it will all remain the same:

          .sort( function ( a, b ) {
            return a.toLowerCase() > b.toLowerCase();
          } )
    

    http://live.datatables.net/gejojiqu/100/edit

    Your other option is to use an Intl Collator in the sort which has options to do a case insensitive sort.

    Allan

This discussion has been closed.