关于bootstraptable的使用

bootstraptable作为常用的表格控件一直拥有者很多的忠实用户,本人原来使用过一次,但是今天再次使用时又再次翻看文档,古做记录,方便下次使用,也给没用过的朋友可以做一些借鉴。 

bootstraptable官网地址:https://examples.bootstrap-table.com/index.html

项目环境介绍:

使用的是模板引擎:thymleaf,在语法上和传统的页面有些区别,不过也只是该写路径的标签而已

第一步:引入所需的文件

<-- 引入4.0版本的bootstrap.css,table使用了部分这个css的样式-->

<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"/>

<-- 引入bootstrap特有的css文件-->
<link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.15.2/dist/bootstrap-table.min.css"/>

<--引入bootstraptable特有的js文件-->

<script src="https://unpkg.com/bootstrap-table@1.15.2/dist/bootstrap-table.min.js"></script>

<--引入4.0版本bootstrap的js文件-->

<script src="https://cdn.bootcss.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<-- 这个是语言包,有了这个才能支持中文,这个就是bootstrap-table支持国际化的核心所在-->
<script src="https://unpkg.com/bootstrap-table@1.15.2/dist/locale/bootstrap-table-zh-CN.min.js"></script>

第二步:创建table容器

bootstrap-table的使用有两种方式,第一种就是传统的html的方式,直接写死dom,第二种就是动态渲染也就是给一个请求地址,根据请求地址返回的值来渲染dom,这个也是最常用的方式。

    <table id="testtable" class=" table-striped">

第三步:进行渲染和填值(此处赋值是直接写死的,也可以写url进行动态赋值)

  $("#testtable").bootstrapTable({
               columns: [{
                   field: 'id',
                   title: 'Item ID'
               }, {
                   field: 'name',
                   title: 'Item Name'
               },{
                   field: 'price',
                   title: 'Item Price'
               }],
               data: [{ //数据
                   id: 1,
                   name: 'Item 1',
                   price: '$1'
               }, {
                   id: 2,
                   name: 'Item 2',
                   price: '$2'
               }, {
                   id: 3,
                   name: 'Item 3',
                   price: '$2'
               }, {
                   id: 4,
                   name: 'Item 4',
                   price: '$2'
               }]
           });

完成

可以看到上面的图标还是比较单调的,官方给了我们几种风格,可以给table标签加class的方式来使用或者组合样式

 

备注:其实所有的答案都在官网,不然就是在代码里,现在只是在做知识的搬运工。

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值