Hide and show button in a Datatable with jquery

Asked

Viewed 429 times

1

I have to show or hide a button inside my Datatable as an ajax function returns.

I can already hide (hide all by default) and already know when to show the button, the problem is that I can not show the specific button of that TR.

This is my job:

$JQuery(document).ready(function() {
    $JQuery(".regra").hide();
    $.post("/main/conciliacao/botao", {id:<?php echo $id ?>, processo:<?php echo $processo ?>}, function(d) {
        if (d !== "false") {
            var aux = d.split(":");
            for (i = 0; i < aux.length; i++) {
                var n = aux[i].replace(/[^\d]+/g, '');
                $("tbody>tr").each(function(index, tr) {
                    var id = tr.cells[0].innerHTML;
                    if (n == id) {
                        var botoes = tr.cells[4].innerHTML;
                        alert(botoes);
                    }
                });
            }
        }
    });
});

I can already access what’s on the button Cell:

<a class="grid" href="javascript:void(0)" title="Arrumar erros"><i class="glyphicon glyphicon-th-list"></i></a>&nbsp;&nbsp;&nbsp;<a style="display: none;" class="regra" href="javascript:void(0)" title="Aplicar regra"><i class="glyphicon glyphicon-book"></i></a>&nbsp;&nbsp;&nbsp;

My problem is I can’t find anything to use .show() that shows only the button of that TR.

1 answer

2


@Sef, you can use a second parameter in the jQuery selector. If you inform it, it will fetch only the DOM objects that are inside it. So to do what you want, you have to search for all DOM objects with the rule class within the tr current.

$("tbody>tr").each(function(index, tr) {
    tr = $(tr);
    var link = $(".regra", tr);
    link.show();

    var id = tr.cells[0].innerHTML;
    if (n == id) {
        var botoes = tr.cells[4].innerHTML;
        alert(botoes);
    }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.