如何防止数据表中特定列的行单击功能?

时间:2016-04-19 13:34:00

标签: javascript jquery datatable

我正在处理带有可点击行的javascript数据表。每一行都有onclick函数,但是在我的一列中我有不同的链接打开jquery对话框,在这列上我要禁用行点击方法,怎么做? 这是我实现行点击的功能

$(rec' tbody').on( 'click', 'tr', function () {

});

5 个答案:

答案 0 :(得分:5)

您必须禁用该特定列的行单击

$('rec' tbody'').on('click', 'td', function () {

         if ($(this).index() == 4 ) { // provide index of your column in which you prevent row click here is column of 4 index
             return;
         }

            // you can do additional functionality by clicking on this column here                         
    });

答案 1 :(得分:1)

您可以查看点击的内容是否为锚点

$(rec' tbody').on( 'click', 'tr', function (evt) {
    if ( $(evt.target).is("a") ) {
        return;
    }
    /* do whatever here */
});

或其他选项是停止从链接/单元传播事件。

答案 2 :(得分:0)

使用类或其他内容来标识您不希望被点击的行/列,并检查点击事件是否来自此元素并使用event.preventDefault()  取消行动。

答案 3 :(得分:0)

您可以尝试为每个要为特定内容点击的列设置类,并且不可点击其他内容。

<table>
  <tr>
    <td class="clickable">click this</td>
    <td class="clickable">and this</td>
    <td class="something-else">but not this</td>
  </tr>
</table>

然后让你的jQuery在类上做一些事情而不是<tr>

$(".clickable").click(function(){
  alert('hello');
});

答案 4 :(得分:0)

可接受的答案有效,但是可能有些人希望与该行进行交互,而不是单击该列。对于这些情况,请尝试以下操作:

if ($thing->trashed()) {
    // do something
}
相关问题