Sorted select list with selectize.js?

Sorted select list with selectize.js?

epep Posts: 24Questions: 6Answers: 0

Hi,

I use selectize.js and the following code

$(document).ready(function() {
  editor = new $.fn.dataTable.Editor( {
    ajax: '/online-erfassung/edit-table.php',
    table: '#kledit',
    fields: [
      { label: '1. Verfasser', 
        name:  '_100_1_a', 
        options: [],  
        type: 'selectize', 

        opts: {
          valueField: 'NAMEN',
          labelField: 'NAMEN',
          searchField: 'NAMEN',
          sortField: 'NAMEN',  // Sorting does not work ??
          create: true,
          load: function( query, callback ) {
                  if ( query.length <= 1 ){ return callback()};
                  $.ajax({
                    url: "/cgi-bin/online-erfassung/2014/select-data.pl",
                    type: 'GET',
                    dataType: 'json',
                    data: { start: query,  col: "NAMEN", table: "PERSONENNAMEN", endtrunkierung: "1" },
                    error: function() { callback(); },
                    success: function(res) { callback(res); },
                    // success: function(res) { alert( "Press Enter" ); callback(res); },
                    create: function (input){ return {name: _100_1_a, text: input }}
                  });
                }
        }


      { label: more labels ... }

    }
    formOptions: {
      main: {
        onReturn: false, 
        onBlur: "submit"
      }
    } 
    more code ...
  });
});

my problem is that the select list returned is not sorted even though the JSON response from the server is sorted alphabetically. An excerpt of the JSON data is for example:

[{"NAMEN":"Grasso, Elsa"},{"NAMEN":"Grasso, Giuseppe"},{"NAMEN":"Grasso, Luciana"},{"NAMEN":"Grasso, Maurizio"},{"NAMEN":"Grasso, Paolo"}]

Alas, when I activate the commented line 26 containing "Press Enter", and deactivate the previous line 25, the select list will be sorted. Besides the fact that I con't understand why, I generally would prefer a sorted select list since a sorted list is better understandable by the user.

Is there any possibility to get a sorted list without the otherwise unnecessary alert command?

Thanks,
Eberhard
~
~

Answers

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Can you sort the data in your select-data.pl script? I'm afraid I don't know if Selectize has an option for sorting inbound data, you'd need to check their documentation, but I suspect it will be down to the data source to order the data.

    Allan

  • epep Posts: 24Questions: 6Answers: 0

    The data from select-data.pl is already sorted.

    Eberhard

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    So are you saying that Selectize is showing the list unsorted!? Even although it is being passed in as sorted?

    Do you have a link to the page?

    Allan

  • epep Posts: 24Questions: 6Answers: 0

    Hi Allan,

    yes, that's what I am saying.

    I have sent you a private message containing the url.

    Eberhard

  • l.garcia-fresca@texlarenovables.coml.garcia-fresca@texlarenovables.com Posts: 2Questions: 0Answers: 0

    Try this for sorting in selectize opts. It works for me.

    sortField: [
         {field: 'NAMEN',direction: 'asc'}
                            ]
    
This discussion has been closed.