繁体   English   中英

隐藏jQuery dataTable中的列

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM