Bootstrap表滤波器控件选择匹配子集

发布于 2025-01-30 14:03:46 字数 2517 浏览 1 评论 0 原文

我正在使用Bootstrap-table和Bootstrap-table滤波器来过滤表中的结果,但是“选择”过滤器是匹配匹配过滤器的字符串子集。例如,如果我选择(不搜索)“燕麦”,我会在“ goatherd”以及“燕麦”的列中获得匹配项。显然,它是在进行某种字符串搜索,而不是匹配整个值。有没有办法改变这种行为?

示例HTML:

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/bootstrap-table.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></head>

      <table id="table" data-url="json/data1.json" class="dataframe" data-filter-control="true" data-show-search-clear-button="true" data-show-filter-control-switch="true">
      <thead>
        <tr style="text-align: right;">
          <th data-field="oats_goats" data-filter-control="select">Porridge or milk</th>
        </tr>
      </thead>
      <tbody>[Insert data]</tbody>
    </table>
    
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"</script>
<script src="https://unpkg.com/[email protected]/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/extensions/filter-control/bootstrap-table-filter-control.min.js"></script>

<script>
  $(function() {
    $('#table').bootstrapTable()
  })
</script>

I'm using bootstrap-table and bootstrap-table-filter to filter results in a table, however the "select" filter is matching subsets of strings which match the filter. E.g., if I select (not search) for "oat", I get matches in the column for "goatherd" as well as for "oat". It's obviously doing some kind of string search rather than matching whole values. Is there a way to change this behaviour?

Example html:

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/bootstrap-table.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></head>

      <table id="table" data-url="json/data1.json" class="dataframe" data-filter-control="true" data-show-search-clear-button="true" data-show-filter-control-switch="true">
      <thead>
        <tr style="text-align: right;">
          <th data-field="oats_goats" data-filter-control="select">Porridge or milk</th>
        </tr>
      </thead>
      <tbody>[Insert data]</tbody>
    </table>
    
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"</script>
<script src="https://unpkg.com/[email protected]/dist/bootstrap-table.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/extensions/filter-control/bootstrap-table-filter-control.min.js"></script>

<script>
  $(function() {
    $('#table').bootstrapTable()
  })
</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小傻瓜 2025-02-06 14:03:46

尝试使用列选项 filtertrictsearch

&lt; th data-field =“ oats_goats” data-filter-control =“ select” data-filter-strict-search =“ true”&gt; porridge或porridge或牛奶&lt;/th&lt;/th&lt;/th&gt; /代码>

Try using the column option filterStrictSearch.

https://bootstrap-table.com/docs/extensions/filter-control/#filterstrictsearch

<th data-field="oats_goats" data-filter-control="select" data-filter-strict-search="true">Porridge or milk</th>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文