I would store original event listeners right after initilization. In the example below I preserve all events for the very first <th>
by saving them to an array map events
:
var table = $('#example').DataTable({
initComplete: function() {
$.each($._data($('#example thead th')[0], 'events'), function(name, obj) {
events[name] = obj[0]
})
}
})
Now you have a map of the "native" dataTables events on the form
events['click'] => old event handler
events['keypress'] => old event handler
...
And then it is really simple to turn sorting (and other dataTables event-driven features) on and off for a particular header (or all headers). Here is a small demo with disable / enable buttons :
//remove original event listeners, add alternative
$("#disable").click(function() {
$("#example thead th:nth-child(1)")
.unbind()
.bind('click', function() {
alert('all listeners removed')
})
})
//restore any original event
$("#enable").click(function() {
var $th = $("#example thead th:nth-child(1)")
$th.unbind()
for (var name in events) {
$th.bind(name, events[name])
}
})
demo -> http://jsfiddle.net/8sbcage4/ (disables / enables dataTables events for the first header)