Php Datatables:基于数据库值隐藏列

Php Datatables:基于数据库值隐藏列,php,jquery,mysql,ajax,datatables,Php,Jquery,Mysql,Ajax,Datatables,我正在尝试根据数据库值显示/隐藏列。我正在使用Jquery、PHP和MySQL 我使用ajax检索数据并隐藏列,但它不隐藏tbody数据,只隐藏标题: $(function () { //----------------------------------------------------------------------- // 2) Send a http request with AJAX http://api.jquery.com/jQuery.ajax/

我正在尝试根据数据库值显示/隐藏列。我正在使用Jquery、PHP和MySQL

我使用ajax检索数据并隐藏列,但它不隐藏tbody数据,只隐藏标题:

$(function () 
  {
    //-----------------------------------------------------------------------
    // 2) Send a http request with AJAX http://api.jquery.com/jQuery.ajax/
    //-----------------------------------------------------------------------
    $.ajax({                                      
      url: 'account-number.php',                  //the script to call to get data          
      data: '',                        //you can insert url argumnets here to pass to api.php
                                       //for example "id=5&parent=6"
      dataType: 'json',                //data format      
      success: function(data)          //on recieve of reply
      {
        var user = data[1];              //get id
        var table = data[2];            //get table name 
        var show = data[4];          //display or hide
        //--------------------------------------------------------------------
        // 3) Update html content
        //--------------------------------------------------------------------
        //recommend reading up on jquery selectors they are awesome 
        // http://api.jquery.com/category/selectors/
        if (show == 0)
        $('#'+ table +'tbody td:nth-child(1), #' + table + 'thead th:nth-child(1)').hide();
        //$('#'+ table +'td:nth-child('+ column +'),th:nth-child('+ column +')').hide();
        if (show == 1)
        $('#'+ table +'tbody td:nth-child(1), #' + table + 'thead th:nth-child(1)').show();
      } 
    });
  }); 
控制台中对此没有错误。在Jquery中,是否有基于数据库值隐藏/显示带有datatables的表数据的特定方法


任何帮助或建议,将不胜感激

我以前没看过这篇文章

但这对我帮助很大

我改变了这一点:

 if (show == 0)
            $('#'+ table +'tbody td:nth-child(1), #' + table + 'thead th:nth-child(1)').hide();

 if (show == 1)
            $('#'+ table +'tbody td:nth-child(1), #' + table + 'thead th:nth-child(1)').show();
为此:

if (show == 0)
        oTable.fnSetColumnVis( 0, false );

if (show == 1)
        oTable.fnSetColumnVis( 0, true );