how to show and hide columns of using datatable jquery

Viewed 16857

I need to show and hide the columns of the datatable after doing a javascript test, but it doesn't work good.

This is my test javascript:

if ( $('#commune_to_display').val()==""){
    $('#utable td:nth-child(2)').hide();
    $('#commune_to ').hide();
}

This test works just in the first page of the datatable, after pagination the column is still visible.

How can I fix it? thanks for help

2 Answers
Related