如何在jquery数据表中使表行无法点击?

时间:2012-07-04 12:43:25

标签: jquery datatables

使用jQuery Datatables列出用户,并使用selectable属性选择和取消选择行。现在我有一个问题,我想让一行不可点击(即登录用户的行)...我怎么能这样做...任何帮助将不胜感激

$('#example tr').click( function() { 

}

如何为特定行禁用此功能?

3 个答案:

答案 0 :(得分:0)

这样的东西? (将class="trDisable"添加到不具有点击功能的行中)

$('#example tr').not("#example tr.trDisable").click( function()

$('#example tr.trDisable').click( function(e) {
    e.stopPropagation()
}

答案 1 :(得分:0)

我想到了两种方式

1每个()用法

$('#example tr').each(function(i) {
    if ( i === 2 ) {//this will select third tr
      $(this).off();
    }
});

2 eq()用法//我不确定这是否适用于表,也许index()将

var disabledRow = $('#example tr').eq(2);//this will deactive third row
if ( contition ) {
  disabledRow.off();
}

你可以阅读这些问题,他们应该帮助

jquery disable click until animation is fully complete

how to define condition with clicked objet's parent?

答案 2 :(得分:0)

我知道这是一个旧帖子,但可能对某人有所帮助..

        $('#example').on('click', 'tbody tr', function () {
            var table = $('#example').DataTable();

            // Check if any rows are selected
            if (table.row(this, { selected: true }).any()) {
                // if condition here, if not valid
                if (!condition) table.row(this).deselect();
            }
        });