Need Help on maintaining the checkbox state when fixed columns enabled

Need Help on maintaining the checkbox state when fixed columns enabled

pboltpbolt Posts: 1Questions: 0Answers: 0
edited October 2011 in DataTables 1.8
Hi,

Can anyone help me in how to maintain the checkbox state when fixed column is enabled.

Please find the below code:

var oTable = $('#example').dataTable({

"bPaginate": true,
"bScrollCollapse": true,
"sScrollY": "450px",
"sScrollX": "100%",
"sScrollXInner": "130%",
"bFilter": false,
"bAutoWidth": false,
"bInfo": false,
"aaSorting": arr,
"sPaginationType": "full_numbers",
"fnDrawCallback": function ( oSettings ) {
$('[type=checkbox]').each( function () {
if(typeof(oTable)!="undefined"){
var iPos = oTable.fnGetPosition( this );
if (iPos!=null) {
var aData = oTable.fnGetData( iPos );
if (jQuery.inArray(aData[0], selected)!=-1)
$(this).addClass('row_selected');
}

$('[type=checkbox]').click( function () {
var iPos = oTable.fnGetPosition( this );
var aData = oTable.fnGetData( iPos );
var iId = aData[0];
is_in_array = jQuery.inArray(iId, selected);

if (is_in_array==-1) {
selected[selected.length]=iId;
}else {
selected = jQuery.grep(selected, function(value) {
return value != iId;
});
}

if ($(this).hasClass('row_selected') ) {
$(this).removeClass('row_selected');
}else {
$(this).addClass('row_selected');
}
});
}
});
}
});

The above code seems to work for previous version of Fixed Columns but not for the latest one.

Replies

  • liuquan0722liuquan0722 Posts: 1Questions: 0Answers: 0
    You should move the drawcallback block into the drawcallback block in the FixedColumns
    Please refer to the below code:
    "fnInitComplete": function(){
    new FixedColumns(tradeQueryTable,{
    "iLeftColumns": 2,
    "sLeftWidth": 'relative',
    "iLeftWidth": 34,
    "fnDrawCallback" : function() {
    $(tableId + "Container").find('input:checkbox').each(function(){
    $(this).attr('checked',$.checkCheckboxState($(this).val()));
    });
    $("#checkAll").attr('checked',selectedAll);

    });
    }
  • pboltnewpboltnew Posts: 1Questions: 0Answers: 0
    Hi,

    I have added the "fnDrawCallback" code in Fixed Columns.but still it is not working.
    The iPos value i.e the position of checkbox is coming as null.

    Please find the code below:
    [code]
    $(document).ready(function() {
    var oTable = $('#example').dataTable({
    "bPaginate": true,
    "bScrollCollapse": true,
    "sScrollY": "450px",
    "sScrollX": "100%",
    "bFilter": false,
    "bAutoWidth": false,
    "bInfo": false,
    "aaSorting": [[1, 'desc']],
    "sPaginationType": "full_numbers"

    });

    new FixedColumns(oTable,{

    "iLeftColumns": 2,
    "sLeftWidth": 'relative',
    "iLeftWidth": 34,
    "fnDrawCallback": function ( oSettings ) {
    $('[type=checkbox]').each( function () {
    if(typeof(oTable)!="undefined"){
    var iPos = oTable.fnGetPosition( this );
    if (iPos!=null) {
    var aData = oTable.fnGetData( iPos );
    if (jQuery.inArray(aData[0], selected)!=-1)
    $(this).addClass('row_selected');
    }

    $('[type=checkbox]').click( function () {
    var iPos = oTable.fnGetPosition( this );
    var aData = oTable.fnGetData( iPos );
    var iId = aData[0];
    is_in_array = jQuery.inArray(iId, selected);

    if (is_in_array==-1) {
    selected[selected.length]=iId;
    }else {
    selected = jQuery.grep(selected, function(value) {
    return value != iId;
    });
    }

    if ($(this).hasClass('row_selected') ) {
    $(this).removeClass('row_selected');
    }else {
    $(this).addClass('row_selected');
    }
    });
    }
    });
    }


    });
    [/code]
    Please help me in resolving this.I am not able to proceed further.
    Its very critical for me to resolve this issue.

    Thanks In Advance
This discussion has been closed.