【问题标题】:Bootstrap-Table filterBy Not Working引导表过滤器不工作
【发布时间】:2017-01-06 16:28:38
【问题描述】:

我正在尝试对通过 JSON 填充的表进行一些过滤(使用 bootstrap-table by wenzhixin)。

部分 HTML:

<button class="btn btn-primary" id="filterBtn">Filter</button>

<div class="container">
    <table class="table table-bordered table-hover" id="table">
        <thead>
        <tr>
            <th data-field="make">Make</th>
            <th data-field="model">Model</th>
            <th data-field="year">Year</th>
        </tr>
        </thead>
    </table>
</div>

部分 JS:

// JSON file is input from a successful AJAX call.
function populateTable(json) {
    $('#table').bootstrapTable({
        data: json
    })
}

// a button is click in html which calls this function.
function filterBy(model) {
    console.log("filterBy is called");
    $('#table').bootstrapTable('filterBy', {
        make: [model]
    });
}

表格正确地填充了所有数据,但是一旦我点击按钮,我就会看到 filterBy() 被调用,但所发生的只是看起来页面刷新了,但表格中的所有数据仍然存在,就像没有过滤一样发生了。

我尝试将make: [model] 更改为make: ["Honda"] 只是作为测试,但它仍然不起作用。它仍然执行相同的行为,即在所有数据仍然完好无损的情况下刷新页面。

不确定我做错了什么。

【问题讨论】:

  • 您可以使用数据表 [datatables.net],它提供了许多有用的方法(filter() 就是其中之一)。它会让你的事情变得更容易

标签: javascript jquery html twitter-bootstrap bootstrap-table


【解决方案1】:

https://github.com/wenzhixin/bootstrap-table/commit/de867d379a46b377efa7eef83fdf898b9073b28c

这是我认为在功能版本:1.11.0 之后的问题。检查 bootstrap-table.js 并找到它。我希望它能解决你的问题。祝你好运!

【讨论】:

    猜你喜欢
    • 2021-04-12
    • 2016-02-13
    • 2020-08-23
    • 2019-01-28
    • 2012-08-01
    • 2023-03-21
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多