If you want to sort a column in a datatable based on a select, you can use the example from datatable site (https://datatables.net/examples/plug-ins/dom_sort.html), but you have to change it a little bit to enable sorting on the text rather than on the value. In the example it says to add:
{ "orderDataType": "dom-select" }
and
/* Create an array with the values of all the select options in a column */
$.fn.dataTable.ext.order['dom-select'] = function ( settings, col )
{
return this.api().column( col, {order:'index'} ).nodes().map(function(td,i ) {
return $('select', td).val();
});
}
This will sort the column to the value of the options.
To sort to text value I changed the function above a little bit:
/* Create an array with the values of all the select options in a column */
$.fn.dataTable.ext.order['dom-select'] = function ( settings, col )
{
return this.api().column( col, {order:'index'} ).nodes().map(function(td,i ) {
//return $('select', td).val(); // <== the original solution
var idx = $('select', td)[0].selectedIndex;
var elm = $('select', td)[0][idx];
// elm is the HTML element
var s = elm.text;
s = s.replace(/(<([^>]+)>)/gi, "");
// s contains the string value of the option
return s;
});
}
Now the column will be sorted on the visible value when a user clicks on the column header.
I hope it wil work for you as well!