利用bootstrap Table自身的定时刷新数据功能,不用编写刷新代码,只需要设置属性和添加对应的js引用即可,还可以通过页面启用或禁用自动刷新功能。
1. 页面组件代码
<div class="col-sm-12 select-table table-striped">
<!-- data-auto-refresh设置true为启用自动刷新插件
data-auto-refresh-interval为每次自动刷新发生的时间(以秒为单位)默认60。
data-auto-refresh-silent设置为true可以自动无提示刷新。默认: true
data-auto-refresh-status 设置true为启用自动刷新。这是表加载时自动刷新的状态。单击按钮切换此属性。
这只是自动刷新的默认状态,因为用户始终可以通过单击按钮来更改它。 默认: true -->
<table id="bootstrap-table" data-auto-refresh="true" data-auto-refresh-interval="30"></table>
</div>
2. 添加依赖的js
<th:block th:include="include :: bootstrap-table-auto-refresh-js" />
对应的实际js
<!-- 表格自动刷新插件 -->
<div th:fragment="bootstrap-table-auto-refresh-js">
<script th:src="@{/ajax/libs/bootstrap-table/extensions/auto-refresh/bootstrap-table-auto-refresh.js?v=1.18.3}"></script>
</div>
3. 页面显示
显示了一个定时刷新的图标。
通过定时刷新图标,可以启用或者停用自动刷新。
当自动刷新处于启动状态时,数据库中数据改变时,可以通过定时刷新显示在页面上。
更多推荐
bootstrap Table实现定时刷新(自动刷新)数据功能
发布评论