Hide and show button in a DataTable with jquery

0

I have to show or hide a button inside my DataTable as the return of an ajax function.

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

This is my role:

$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 in 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 that I do not think anything to use .show() that just shows the button of that TR.

    
asked by anonymous 06.02.2015 / 11:40

1 answer

2

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

$("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);
    }
});
    
06.02.2015 / 12:01