[英]hide columns in jQuery dataTable
我正在使用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
1第一欄隱藏。 同樣,第4-8列也應根據某些條件隱藏/顯示。 但是他們沒有躲藏。 在表中,顯示了所有列。
我在互聯網上搜索了此內容,但沒有任何解決方案有幫助。
bVisible
屬性是一個布爾值,它不支持函數。 但是,您可以做的是將邏輯移到initComplete
函數中,並使用column().visible()
隱藏所需的列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.