Select2 multiselect - How to stop initial display sorting?

Select2 multiselect - How to stop initial display sorting?

HisanoriHisanori Posts: 4Questions: 1Answers: 0

select2 sorts server responses.
How can I stop the sorting?

Sorting on selection is solved by the following method and no problem.
https://datatables.net/forums/discussion/33219/select2-multiple-select-options-order

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin
    Answer ✓

    Hi,

    You'd be best asking in the Select2 support channels if this is a select issue. That said, I'm surprised by that - I though it just displayed the data in the order you gave it. Perhaps you can link to the page so I can confirm what is going on?

    Allan

  • mguinnessmguinness Posts: 85Questions: 12Answers: 1
    Answer ✓

    I don't think they're talking about the order of the options in the list, but rather the order of selected items as described In multi-select, selections do not appear in the order in which they were selected.

    If OP is talking about the ordering of selected items on control initialization that could be tricky. For example if you have select options { "Blue": 1, "Green": 2, "Red": 3 } but the selected values from DB are 3,2,1 it wouldn't display selections in that order.

  • HisanoriHisanori Posts: 4Questions: 1Answers: 0

    Hi,
    Thanks for the reply.
    I'll ask the question on the select2 site.
    I am developing in a local environment, so I cannot paste my site.
    I will paste the URL when the server is ready.
    Thank you for your advice.

  • HisanoriHisanori Posts: 4Questions: 1Answers: 0

    I will wait for the following pull request to be resolved and closed.

    Add SelectionOrder DataAdapter decorator and related options

    Thank you.

  • HisanoriHisanori Posts: 4Questions: 1Answers: 0

    I sorted the DOM by referring to the raw data.
    It was solved.
    Thank you.

          editor.on('open', function (e, o, action) {
              var node = editor.node('codecs[].codec');
              var select = node.getElementsByTagName('select')[0];
              var options = node.getElementsByTagName('option');
              var codecs = table.rows({selected:true}).data()[0].codecs;
              for (var i=0; i < codecs.length; i++) {
                  for (var j=0; j < options.length; j++) {
                      if (codecs[i].codec == options[j].value) {
                          select.appendChild(options[j]);
                          break;
                      }
                  }
              }
          });
    
  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin

    Nice one - thanks for posting you solution :).

    Allan

This discussion has been closed.