1

I've been trying to see if this is even possible, so let me explain what I'm looking for.

I have a basic table that I'm making sortable with jQuery DataTables, no custom options, just the simple basic initialization.

$("#myTable").DataTable();

Is there a way that I connect myTable to a select form element, and have the table be sortable by that select dropdown ONLY?

1
  • This might help, stackoverflow.com/q/16565568/1793718 Basically if the user chooses an option in the select element one will expect the column to be filtered(instead of sorting). So I think its better to filter the data and display it. Please see my question here, stackoverflow.com/q/39169291/1793718 I couldn't find a better solution. You might need to write some custom plugin to do that. Or head to datatables.net/forums and post your question there for other solutions Commented Jul 12, 2017 at 14:07

1 Answer 1

0

You can disable sorting for each column using columnDefs.orderable option and then sort the table with order() API method when value of drop-down control changes.

For example:

var table = $('#example').DataTable({
   'columnDefs': [
      { 'orderable': false, 'targets': '_all' }
   ],
   'order': [0, 'asc']       
});

$('#example-sort').on('change', function(){
   table.order([$(this).val(), 'asc']).draw();
})   

See this example for code and demonstration.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.