how to disable sorting click event on table header children
how to disable sorting click event on table header children
Hi!
Based on the following example in https://datatables.net/examples/api/multi_filter.html I'm rendering my table header as input fields allowing custom filtering for each table column:
$('#example thead th').each( function () {
var title = $('#example thead th').eq( $(this).index() ).text();
$(this).html( '<input type="text" placeholder="Search '+title+'" />' );
} );
However, currently sorting of the column is triggered on each click on a th node AND its children. This means each time I put the cursor to an input field the click triggers sorting of the column.
Is there a way to disable firing this event for the input field but leave it for the th node?
I've already tried the suggestions in http://datatables.net/forums/discussion/3638/disable-sorting-when-clicking-on-headers but they seem to be for a previous Datatables version.
$('.dataTables_scrollHead thead th').unbind('click.DT');
disables the click event for the whole th node, but I'm not sure how to use https://datatables.net/reference/api/order.listener() for changing the click handling.
Thx, for helping me out!
This question has an accepted answers - jump to answer
Answers
I am use select inputs (http://datatables.net/examples/api/multi_filter_select.html)
And resolve this problem in next code:
js
var $select = $('<select><option value=""></option></select>').on( 'click', function(e) {
console.log(" click on select in column =" + $column.data());
e.stopPropagation();
} );
Now i have two feature: select input and sort independent of each other
Thx lit_uriy! Works for me!
I'm adding my example to https://datatables.net/examples/api/multi_filter.html