如何禁用DataTables / TableTools按钮 [英] how to disable a DataTables/TableTools button

查看:1677
本文介绍了如何禁用DataTables / TableTools按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用DataTable 1.10和TableTools 2.2.1。



鉴于以下剪切,我想禁用/启用编辑按钮。

  var myTable = $(#myTable).DataTable({
tableTools:{
aButtons:[{
sExtends:text,
sButtonText:Edit,
fnClick:function(nButton,oConfig,oFlash){
/ *某些东西* /
}
}]
}
})

有没有可能在运行时这样做?



感谢很多

解决方案

这是一个很好的问题!似乎

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

只是对其他地方存储的事件的引用,不可访问更改 fnClick 对API没有影响)。但是,您可以使用预定义的类 DTTT_disabled ,并检查您的 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');
}
}]
}
});

示例,复选框启用或禁用按钮:



()($(this).is(':checked)($($) ')){
$('。DTTT_button_text')。removeClass('DTTT_disabled');
} else {
$('。DTTT_button_text' b $ b}
});

请参阅demo - > http://jsfiddle.net/ev2N2/


I'm using DataTable 1.10 and TableTools 2.2.1.

Given the following snipped I would like to disable/enable the edit-button.

var myTable = $("#myTable ").DataTable({
tableTools : {
    "aButtons" : [ {
        "sExtends" : "text",
        "sButtonText" : "Edit",
        "fnClick" : function(nButton, oConfig, oFlash) {
            /* some stuff */    
        }
    }]
  }
})

Is there a possibility to do this at runtime?

Thanks a lot

解决方案

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/

这篇关于如何禁用DataTables / TableTools按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆