Bootstrap表格插件Bootstrap Table配置教程

Bootstrap Table快速入门教程,本文演示了前端加载数据和服务器端加载数据的最基本的配置。

依赖环境

        1,bootstrap-4
        2,jquery

网页引用文件

<script src="https://www.itxst.com/package/bootstrap-table-1.14.1/jquery-3.3.1/jquery.js"></script>
<link href="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet" />
<link href="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-table-1.14.1/bootstrap-table.css" rel="stylesheet" />
<script src="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-table-1.14.1/bootstrap-table.js"></script>

配置说明:

   1,columns 需要显示的列表

var   columns=[{
                field: 'Id',
                title: '编号'
            }, {
                field: 'ProductName',
                title: '产品名称'
            }, {
                field: 'StockNum',
                title: 'Item 库存'
            }];

   2,data需要显示的数据

    var  data=[{
                Id: 1,
                ProductName: '香蕉',
                StockNum: '100'
            }, {
                  Id: 2,
                ProductName: '苹果',
                StockNum: '200'
            }]

前端加载数据例子

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script src="https://www.itxst.com/package/bootstrap-table-1.14.1/jquery-3.3.1/jquery.js"></script>
<link href="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet" />
<link href="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-table-1.14.1/bootstrap-table.css" rel="stylesheet" />
<script src="https://www.itxst.com/package/bootstrap-table-1.14.1/bootstrap-table-1.14.1/bootstrap-table.js"></script>
    <title>Bootstrap Table入门例子</title>
    <style>
        .table-demo {
        width:80%;
        margin:30px auto 0px auto;
        }
    </style>
</head>
<body>
    <div class="table-demo">
        <table id="table"></table>
    </div>
    <script>
      //设置需要显示的列
        var columns = [{
            field: 'Id',
            title: '编号'
        }, {
            field: 'ProductName',
            title: '产品名称'
        }, {
            field: 'StockNum',
            title: 'Item 库存'
        }];


        //需要显示的数据
        var data = [{
            Id: 1,
            ProductName: '香蕉',
            StockNum: '100'
        }, {
            Id: 2,
            ProductName: '苹果',
            StockNum: '200'
            }];
        //bootstrap table初始化数据
        $('#table').bootstrapTable({
            columns: columns,
            data: data
        });
 
    </script>
</body>
</html>

服务端加载数据例子

       //设置需要显示的列
        var columns = [{
            field: 'Id',
            title: '编号'
        }, {
            field: 'ProductName',
            title: '产品名称'
        }, {
            field: 'StockNum',
            title: 'Item 库存'
        }];


        $('#table').bootstrapTable({
            url: 'js/data.json',
            pagination: true,//开启分页
            search: true, //开启刷选
            columns: columns
        });

在线试一试   下载文件