Bootstrap Table簡單例子學習
1、Bootstrap Table簡介
Bootstrap Table是基于Bootstrap的輕量級表格插件,只需要簡單的配置就可以實現強大的支持固定表頭、單復選、排序、分頁、搜索以及自定義表頭等功能。
2、所需要的庫:
bootstrap.min.css
bootstrap-table.css
jquery.min.js
bootstrap.min.js
bootstrap-table.js
3、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 id="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' }, ]});
4、Bootstrap Table簡單的demo:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Bootstrap Table的demo</title> <link rel="stylesheet" href="bootstrap.css"> <link rel="stylesheet" href="bootstrap-table.css"> </head> <body> <table id="table"></table> <!--引入相關的js文件--> <script src="jquery.min.js"></script> <script src="bootstrap.js"></script> <script src="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>
5、Bootstrap Table學習文檔
http://wenzhixin.net.cn/p/bootstrap-table/docs/documentation.html
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!