1

I've tried everything I'm aware of trying to make this work, but I'm still not able to.

All I need is a "select all" checkbox, do a loop to every element to set their classes and save their id in a session variable. So far I get every part of this code, except to visually see the checkbox checked.

Here is my code:

$('#all').on('change', function () {
    if($(this).is(':checked')){
        table.$("input[type='checkbox']").each( function() {
            console.log($(this).attr("id"));
            $(this).prop( "checked" ,true);
            console.log($(this).prop("checked"));
            var id=$(this).attr("id").split('_')[1];
            var id_row=table.row("#row_"+id).index()+1;
            $("#tabla_equipos tr:nth-child(" + id_row + ")").addClass('active');
            $("table.DTFC_Cloned>tbody tr:nth-child(" + id_row + ")").addClass('active');
            funcChechboxes('{{ path('user_session_set')}}',id,'single');
        });
    }else{
        //more code
    }
});

I do get the checkboxes id on the console, and the "true" value for their "checked" prop ... even the class is applied, but not the pretty tick in the box.

console:

e_1
true
e_2
true
e_3
true
e_5
true

Any help would be much appreciated!

Regards.

3 Answers3

1

Look at http://jsfiddle.net/xnxgm1m6/2/

$(document).ready(function(e){
$("#selectall").click(function(){
    var b = false;
    if($(this).is(":checked"))
        b = true;
    $("#table").find("tr").each(function(){
        $(this).find('input[type="checkbox"]').each(function() {
            $(this).prop("checked", b);
            var id=$(this).attr("id").split('_')[1];
            if(b)
                $("#table tr:nth-child(" + id + ")").addClass('active');
            else $("#table tr:nth-child(" + id + ")").removeClass('active');
            //DON'T KNOW WHAT THIS IS FOR
           // $("table.DTFC_Cloned>tbody tr:nth-child(" + id_row + ")").addClass('active');
        //funcChechboxes('{{ path('user_session_set')}}',id,'single');

        });
    });
});

I think is what you want. Hope that helps.

Telmo Silva
  • 335
  • 1
  • 5
1

Finally I got it: Since I'm using DataTable fixedColumns, this api cloned my table (yep, now I've got 2 tables!), and I was pointing to the wrong table (the clone has the checkboxes now).

So the final working code is this:

$('#all').on('click', function () {
    if($(this).is(':checked')){
            $("table.DTFC_Cloned>tbody").find("input[type='checkbox']").each( function() {
                $(this).prop("checked", true).change();
                var id=$(this).attr("id").split('_')[1];
                var id_row=table.row("#row_"+id).index()+1;
                $("#tabla_equipos tr:nth-child(" + id_row + ")").addClass('active');
                $("table.DTFC_Cloned>tbody tr:nth-child(" + id_row + ")").addClass('active');
                funcChechboxes('{{ path('user_session_set')}}',id);
            });
        }else{

Thanks for the help guys!

  • Hey you saved my life, I tried to find a solution in the whole internet, I am using FixedColumns and checkboxes, I will try what you said you should publish it in FixedColumns documentation as a fix, are u brazilian? @Mario Salgado – Roger Oliveira Oct 21 '15 at 03:35
0

This can be solved with.

$("#checkbox-reminder").prop("checked", true).checkboxradio();
$('#checkbox-reminder').checkboxradio('refresh');

See this thread for more info.

Olmstov
  • 563
  • 7
  • 18