如何显示和隐藏使用datatable jquery的列

问题描述:

我需要在进行javascript测试后显示和隐藏数据表的列,但它不能正常工作。

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

这是我的测试javascript:

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

您可以显示/隐藏列,如下所示。只需用您的实际列索引替换 3 4

You can show/hide columns as shown below. Just replace 3 and 4 with your actual column indexes.

var table = $('#utable').DataTable();
table.column(3).visible(true);    // To show
table.column(4).visible(false);   // To hide