bootstrap table小案例

Bootstrap Table是基于Bootstrap的轻量级表格插件,只需要简单的配置就可以实现强大的支持固定表头、单复选、排序、分页、搜索以及自定义表头等功能。

1、所需要的库:

    bootstrap.min.css

    bootstrap-table.css

    jquery.min.js

    bootstrap.min.js

    bootstrap-table.js

2、Bootstrap Table获取数据的方式:

Bootstrap Table通过data属性标签或者JavaScript来显示表格数据:

(1)、通过data属性标签

在表格中设置data-toggle=“table”,此方式可以在不写JavaScript的情况下启用Bootstrap Table。

<table data-toggle="table" data-url="data.json"> <thead> ... </thead> </table>

(2)、通过JavaScipt向表格传入数据:

<table></table> <1>、简单的静态数据 $('#table').bootstrapTable({ columns: [{ field: 'id', title: 'Item ID' }, { field: 'username', title: 'Item Username' }, { field: 'password', title: 'Item Passowrd' }], data: [{ id: 1, username: 'Item 1', passowrd: '$1' }, { id: 2, username: 'Item 2', password: '$2' }]}); <2>、通过url获取数据 $('#table').bootstrapTable({ url: 'data1.json', columns: [{ field: 'id', title: 'Item ID' }, { field: 'username', title: 'Item Username' }, { field: 'passowrd', title: 'Item Passowrd' }, ]});

3、Bootstrap Table简单的demo:

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Bootstrap Table的demo</title> <link href="https://www.jb51.net/bootstrap.css"> <link href="https://www.jb51.net/bootstrap-table.css"> </head> <body> <table></table> <!--引入相关的js文件--> <script src="https://www.jb51.net/jquery.min.js"></script> <script src="https://www.jb51.net/bootstrap.js"></script> <script src="https://www.jb51.net/bootstrap-table.js"></script> <!--自定义javaScript--> <script> $('#table').bootstrapTable({ columns: [{ field: 'id', title: 'Item ID' }, { field: 'username', title: 'Item Username' }, { field: 'passsword', title: 'Item Password' }], data: [{ id: 1, username: 'Item 1', passowrd: '123' }, { id: 2, username: 'Item 2', passowrd: '123 }] }); </script> </body> </html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

如果大家还想深入学习,可以点击这里进行学习,再为大家附两个精彩的专题:Bootstrap学习教程 Bootstrap实战教程

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzdwgg.html