Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82439

How to sort properly content of Select input?

$
0
0

Using Individual column searching (select inputs) as an example, I added 2 select inputs to my table:

    initComplete: function () {
      this.api().columns([1, 8]).every(function (i) {
        var column = this;
        var select = $('<select><option value=""></option></select>')
          .appendTo($("#listofservices thead tr:eq(1) th").eq(column.index()).empty())
          .on('change', function () {
            var val = $.fn.dataTable.util.escapeRegex(
              $(this).val()
            );
            column
              .search(val ? '^' + val + '$' : '', true, false)
              .draw();to extract the value 
          });

        switch (i) {
          case 1:
            column.data().unique().sort().each(function (d, j) {
              select.append('<option value="' + d + '">' + d + '</option>')
            });
            break;
          case 8:
            column.data().unique().sort().each(function (d, j) {
              var sText = $('<a/>').html(d).text();
              select.append( '<option value="' + sText + '">' + sText + '</option>' );
            });
            break;
          default:
        }
      });
    }

The content of the select inputs is currently sorted according to the content of the column.

For the second input (case 8 in the code), the cell is a link (hence the var sText to extract the value).
I would like this select to be sorted by the values.

How can I do that?


Viewing all articles
Browse latest Browse all 82439

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>