【问题标题】:how to use cookie to save filterBy in bootstrap-table如何使用 cookie 在 bootstrap-table 中保存 filterBy
【发布时间】:2017-01-09 01:41:44
【问题描述】:

Cookie可以保存sortOrder、sortName、pageNumber、pageList、columns、searchText、filterControl,但不能保存filterBy。

我要跳转到新页面,返回现有表单可以保留过滤器的结果。

<a id="filterBy">filterBy</a>
<table data-toggle="table" data-cookie="true" data-cookie-id-table="saveId">
    <thead>
    <tr>
        <th>Name</th>
        <th>Stars</th>
        <th data-field="status">Forks</th>
        <th>Description</th>
    </tr>
    </thead>
    <tbody>
    <tr id="tr-id-1" class="tr-class-1">
        <td id="td-id-1" class="td-class-1">
            <a href="https://github.com/wenzhixin/bootstrap-table">bootstrap-table</a>
        </td>
        <td>526</td>
        <td>122</td>
        <td>An extended Bootstrap table with radio, checkbox, sort, pagination, and other added features. (supports twitter bootstrap v2 and v3) 
        </td>
    </tr>
    <tr id="tr-id-2" class="tr-class-2">
        <td id="td-id-2" class="td-class-2">
            <a href="https://github.com/wenzhixin/multiple-select">multiple-select</a>
        </td>
        <td>288</td>
        <td>4</td>
        <td>A jQuery plugin to select multiple elements with checkboxes :)
        </td>
    </tr>
    <tr id="tr-id-3" class="tr-class-3">
        <td id="td-id-3" class="td-class-3">
            <a href="https://github.com/wenzhixin/bootstrap-show-password">bootstrap-show-password</a>
        </td>
        <td>32</td>
        <td>11</td>
        <td>Show/hide password plugin for twitter bootstrap.
        </td>
    </tr>
    <tr id="tr-id-4" class="tr-class-4">
        <td id="td-id-4" class="td-class-4">
            <a href="https://github.com/wenzhixin/blog">blog</a>
        </td>
        <td>13</td>
        <td>4</td>
        <td>my blog</td>
    </tr>
    <tr id="tr-id-5" class="tr-class-5">
        <td id="td-id-5" class="td-class-5">
            <a href="https://github.com/wenzhixin/scutech-redmine">scutech-redmine</a>
        <td>6</td>
        <td>3</td>
        <td>Redmine notification tools for chrome extension.</td>
    </tr>
    </tbody>
</table>
var $table = $('table');
$('#filterBy').click(function() {
    $table.bootstrapTable('filterBy', {
        status: '4'
    });
})

这是我的jsfiddle,谢谢

【问题讨论】:

    标签: jquery twitter-bootstrap bootstrap-table


    【解决方案1】:

    尝试使用扩展添加

    &lt;script src="extensions/cookie/bootstrap-table-cookie.js"&gt;&lt;/script&gt;

    <table 
          data-cookie="true"   <---- here
          data-toggle="table" 
          data-pagination="true" 
          data-search="true" 
          data-filter-control="true" 
          data-show-search-clear-button="true" 
          data-reorderable-columns="true" 
          data-total-rows="true" 
          data-show-footer="true" 
          data-show-toggle="true" 
          data-sortable="true" 
          data-show-columns="true"> 
    <thead>
     . . .
    <thead>
    <tbody>
     . . .
    </tbody>
    </table>
    

    https://bootstrap-table.com/docs/extensions/cookie/查看更多信息

    【讨论】:

      猜你喜欢
      • 2018-05-20
      • 1970-01-01
      • 2023-02-13
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 2015-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多