【发布时间】:2018-04-04 12:43:35
【问题描述】:
我正在使用 jQuery Datatable 在 jsp 页面中呈现表格。表中的列数可能因服务器端而异。 我的代码是:
<th width="10%">Beneficiary Bank</th>
<th width="10%">Depositor's Bank</th>
<th width="10%">Type</th>
<th width="8%">Reference No</th>
<th width="8%">Amount</th>
<th width="8%">Date</th>
<th width="8%">Bonus?</th>
<th width="8%">Remarks</th>
我有 8 列,但根据某些条件,我必须隐藏其中的一些。 我正在渲染这样的表格:
jQuery('#gridTable').dataTable( {
"aaData":data,
"aoColumns": [
{ "mDataProp": "prop1",
"bVisible" : function() {
if(condition1) {
return true;
} else {
return false;
}
}
},
{ "mDataProp": "prop2"
},
{ "mDataProp": "prop3"
},
{ "mDataProp": "propp8",
"bVisible" : function(){
if(condition2) {
return true;
} else {
return false;
}
}
},
{ "mRender": "prop9",
"bVisible" : function(){
if(condition2) {
return true;
} else {
return false;
}
}
},
{ "mDataProp": "prop10",
"bVisible" : function(){
if(condition2) {
return true;
} else {
return false;
}
}
},
{ "mDataProp": "prop11",
"bVisible" : function(){
if(condition3) {
return false;
} else {
return true;
}
}
},
{ "mDataProp": "prop12",
"bVisible" : function(){
if(condition3) {
return false;
} else {
return true;
}
}
},
] ,
"order": []
} );
根据我的代码,取决于condition1 第一列应该隐藏。同样,第 4-8 列也应根据某些条件隐藏/显示。但他们并没有隐藏。在表格中,所有列都显示出来了。
我在互联网上搜索过这个问题,但没有任何解决方案有帮助。
【问题讨论】:
-
仅供参考,您使用的代码是旧数据表版本。较新的版本有不同的语法,你可能会使用新文件但编写旧代码吗?
标签: javascript jquery datatables