1

How can I show and hide columns in datatable.js you see I can enable and disable it BUT the problem is my datable is binded in AJAX source so it automates requests each time I show and hide a column.

Below is the code I used but has no luck in showing and displaying columns without an ajax request.

$(".table-dash1").dataTable().fnSetColumnVis(0, false);

1 Answer 1

1

An example from the DataTables documentation:

$(document).ready(function() {
    $('#example').dataTable( {
        "sScrollY": "200px",
        "bPaginate": false
    } );
} );

function fnShowHide( iCol )
{
    /* Get the DataTables object again - this is not a recreation, just a get of the object */
    var oTable = $('#example').dataTable();



    var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
    oTable.fnSetColumnVis( iCol, bVis ? false : true );
}

Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Great answer, especially since I can't find the solution for version under 1.10. Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.