how to disable a DataTables/TableTools button

十年热恋 提交于 2019-12-04 07:27:41

This was a good question! Seems that the fnClick in

dataTable.tabletools().fnSettings().buttonSet[id].fnClick 

only is a reference to the event stored elsewhere, not accessible (changing fnClick on the API has no effect). However, you can use the predefined class DTTT_disabled and check for that in your fnClick-handler :

var dataTable = $("#example").DataTable({
   sDom: 'TC',
   oTableTools : {
       aButtons : [{
            sExtends : "text",
            sButtonText : "Edit",
            fnClick :  function(nButton, oConfig, oFlash) {
                 if ($(nButton).hasClass('DTTT_disabled')) return;
                 alert('edit button clicked');
            }
       }]  
  }
});

example with a checkbox enabling or disabling the button :

$("#enable").click(function() {
    if ($(this).is(':checked')) {
        $('.DTTT_button_text').removeClass('DTTT_disabled');
    } else {
        $('.DTTT_button_text').addClass('DTTT_disabled');
    }
});

see demo -> http://jsfiddle.net/ev2N2/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!