上のイム私は右initilization後に元のイベントリスナーを格納します。 I以下の例では、配列マップevents
にそれらを保存することで、非常に最初の<th>
のすべてのイベントを保存する:
var table = $('#example').DataTable({
initComplete: function() {
$.each($._data($('#example thead th')[0], 'events'), function(name, obj) {
events[name] = obj[0]
})
}
})
は今、あなたは、フォーム上の「ネイティブ」のDataTableイベントのマップを持って
events['click'] => old event handler
events['keypress'] => old event handler
...
そして、特定のヘッダー(またはすべてのヘッダー)の並べ替え(および他のdataTablesイベントドリブン機能)のオン/オフを切り替えることは本当に簡単です。ここ/無効ボタンを有効にすると小さなデモである:
//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])
}
})
デモ - >http://jsfiddle.net/8sbcage4/(禁止/最初のヘッダのためのDataTableイベントをイネーブル)
の可能な重複が[jqueryののDataTableを使用して、ソートカラムを無効] (http://stackoverflow.com/questions/3932587/disable-a-column-sorting-using-jquery-datatables) – theinarasu
@theinarasu:いいえ、彼の問題は、私が初期化/クリックイベントの後にデータセットの初期化中です。 –
@ CodeDemonの場合、イベントハンドラをbindステートメントに追加してみてください。 –