Im actually implementing jquery datatables plugin to sort and search in tables, in in order to sort columns with select elements (dropdownlist) I had to implement this solution given here:JQuery Datatables sorting a select inside a column, which is:
var table = $('#example').DataTable({columnDefs: [
{
targets: [0,1,2,3],
render: function(data, type, full, meta){
if(type === 'filter' || type === 'sort'){
var api = new $.fn.dataTable.Api(meta.settings);
var td = api.cell({row: meta.row, column: meta.col}).node();
var $input = $('select, input', td);
if($input.length && $input.is('select')){
data = $('option:selected', $input).text();
} else {
data = $input.val();
}
}
return data;
}
} ],});
Actually this code is working good, however the onchange event for those select elements are never fired. So my question is how can I modify this code to make the on change event works for all select elements in the columns?
$(elem).trigger("change")is how you can programmatically trigger event handlers. The better way to do it is to create a function that you call from your change handler as well as anywhere else.