Bootstrap 5 移动第一响应表解决方案

  • 源码大小:157KB
  • 所需积分:1积分
  • 源码编号:19JP-3105
  • 浏览次数:834次
  • 最后更新:2023年05月06日
  • 所属栏目:表格
本站默认解压密码:19jp.com 或 19jp_com

简介

RWD表模式是一个轻量级、易于使用、移动优先、渐进增强的jQuery响应表插件,适用于最新的Bootstrap 5框架。

它会自动将超过屏幕宽度的表格列折叠到下拉菜单中。然后,用户只需单击菜单中相应的复选框,就可以轻松地显示或隐藏所需的表列

此外,该插件支持固定表头和可排序功能,这些功能的增强进一步提高了大型/复杂HTML表的可用性和交互性。

参见:

  • JavaScript和CSS中的10个最佳响应表插件

如何使用它:

1.加载样式表rwd表格.css和JavaScriptrwd-table.js格式在Bootstrap 5项目中。

  1. <!-- jQuery and Bootstrap -->
  2. <link rel="stylesheet" href="/path/to/cdn/bootstrap.min.css" />
  3. <script src="/path/to/cdn/jquery.min.js"></script>
  4. <script src="/path/to/cdn/bootstrap.bundle.min.js"></script>
  5.  
  6. <!-- RWD-Table-Patterns -->
  7. <link rel="stylesheet" href="dist/css/rwd-table.css" />
  8. <script src="dist/js/rwd-table.js"></script>

2.使用CSS类“table responsived”将HTML表包装到DIV容器中。然后通过数据优先级属性

  1. <div class="table-responsive">
  2. <table cellspacing="0" id="example-table" class="table table-small-font table-tighten table-bordered table-striped">
  3. <thead>
  4. <tr>
  5. <th>Index</th>
  6. <th data-priority="1">Last Trade</th>
  7. <th data-priority="2">Trade Time</th>
  8. <th data-priority="3">Change</th>
  9. ...
  10. </tr>
  11. </thead>
  12. <tbody>
  13. ...
  14. </tbody>
  15. </table>
  16. </div>

3.初始化RWD表模式插件。

  1. $(function() {
  2. $('.table-responsive').responsiveTable({
  3. // options here
  4. });
  5. });

4.使用以下参数配置响应表。

  1. $(function() {
  2. $('.table-responsive').responsiveTable({
  3. pattern: 'priority-columns',
  4. stickyTableHeader: true,
  5. fixedNavbar: '.navbar.fixed-top',
  6. addDisplayAllBtn: true,
  7. addFocusBtn: true,
  8. focusBtnIcon: 'fa fa-crosshairs',
  9. mainContainer: window,
  10. sortable: false,
  11. compareFunction: function(a, b, dir) { // for sortable
  12. return a[0].localeCompare(b[0], undefined, { numeric: true }) < 0 ? -dir : dir;
  13. },
  14. i18n: {
  15. focus : 'Focus',
  16. display : 'Display',
  17. displayAll: 'Display all'
  18. }
  19. });
  20. });

5.您也可以初始化插件并通过HTML传递选项数据属性如下:

  1. <div data-responsive-table-toolbar="example-table"></div>
  2. <div class="table-responsive" data-pattern="priority-columns" data-sortable="true">
  3. <table cellspacing="0" id="example-table" class="table table-small-font table-tighten table-bordered table-striped">
  4. <thead>
  5. <tr>
  6. <th>Index</th>
  7. <th data-priority="1">Last Trade</th>
  8. <th data-priority="2">Trade Time</th>
  9. <th data-priority="3">Change</th>
  10. ...
  11. </tr>
  12. </thead>
  13. <tbody>
  14. ...
  15. </tbody>
  16. </table>
  17. </div>

6.当表格数据发生变化时,更新响应表。

  1. $('.table-responsive').responsiveTable('update');

预览截图