【问题标题】:Bootstrap-Table add a default filter on table createBootstrap-Table 在创建表时添加默认过滤器
【发布时间】:2020-04-30 06:45:39
【问题描述】:

我的列过滤器正在工作,我现在要做的是创建一个默认过滤器,它将应用于表创建。

<table id="testTable"
 data-side-pagination="server"> 
            <thead>

                    <tr>
                        <th class="question" data-field="UserFullName" data-sortable="false" data-filter-control="select">Name: </th>
                        <th class="question" data-field="UserJobTitle" data-sortable="false" data-filter-control="select" data-filter-data="var:userJobTitles">JobTitle: </th>
                    </tr>        

            </thead>

<script>
    var userJobTitles = {
            Admin: 'Admin',
            IT: 'IT',
            General : 'General',
            Security : 'Security',
            CEO : 'CEO',
    };
</script>

在此示例中,我想将 IT Jobtitle 设为默认职位。 这似乎接近解决方案bootstrap-table / How to add filter-control in table configuration,问题是我不想在javascript方面这样做。

【问题讨论】:

    标签: bootstrap-table


    【解决方案1】:

    我认为这个功能在 Bootstrap Table 中是开箱即用的。请看:filterDefault column option documentation

    无需为此编写 JavaScript,您只需在与您要过滤的列对应的 &lt;th&gt; 元素上使用 data-filter-default 属性即可。所以你的情况是:

    <th class="question" 
        data-field="UserJobTitle" 
        data-sortable="false" 
        data-filter-control="select" 
        data-filter-data="var:userJobTitles" 
        data-filter-default="IT">JobTitle: </th>
    

    重要提示:必须使用data-filter-data的“密钥”(参见:filterData column option documentation)。

    希望这会有所帮助:)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-02
      • 2012-07-03
      • 2017-05-26
      相关资源
      最近更新 更多