我正在尝试根据数据库值显示/隐藏列。我正在使用 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 中数据表的表数据?
任何帮助或建议,我们将不胜感激!
最佳答案
我之前没看过这篇文章! jquery datatables hide column
但这对我帮助很大。
我改变了这个:
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 );
关于php - 数据表:根据数据库值隐藏列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17402581/