php - Datatables: Hide Column based on database value -


i'm trying show/hide column based on database values. i'm using jquery, php , mysql.

i using ajax retrieve data , hide column, doesn't hide tbody data, header hidden:

$(function ()    {     //-----------------------------------------------------------------------     // 2) send http request ajax http://api.jquery.com/jquery.ajax/     //-----------------------------------------------------------------------     $.ajax({                                             url: 'account-number.php',                  //the script call data                 data: '',                        //you can insert url argumnets here pass 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 on jquery selectors 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();       }      });   });  

there no error in console this. there specific way hide/show table data datatables in jquery based on database value?

any or suggestions, appreciated!

i didn't see post before! jquery datatables hide column

but helped me alot.

i changed this:

 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(); 

to this:

if (show == 0)         otable.fnsetcolumnvis( 0, false );  if (show == 1)         otable.fnsetcolumnvis( 0, true ); 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -