Bootstrap-table學習筆記(一)

第一次使用Bootstrap-table這個表格插件,記錄一下使用過程當中遇到的問題。css

===================jquery

|  引入CSS文件json

<link rel="stylesheet" href="bootstrap.min.css">
<link rel="stylesheet" href="bootstrap-table.css">

 

|  引入相關庫bootstrap

咱們須要引入Jquery庫、bootstrap庫、以及bootstrap-table.js文件url

<script src="jquery.min.js"></script>
<script src="bootstrap.min.js"></script>
<script src="bootstrap-table.js"></script>
<-- put your locale files after bootstrap-table.js -->
<script src="bootstrap-table-zh-CN.js"></script>

|  啓用Bootstrap Table插件:spa

官方文檔中給出了咱們有兩種那個方式來啓用bootstrap-table插件:插件

1,經過data屬性的方式:code

<table data-toggle="table">
    <thead>
        <tr>
            <th>Item ID</th>
            <th>Item Name</th>
            <th>Item Price</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Item 1</td>
            <td>$1</td>
        </tr>
        <tr>
            <td>2</td>
            <td>Item 2</td>
            <td>$2</td>
        </tr>
    </tbody>
</table>

  

2,經過js的方式:blog

//只須要HTML中寫下table標籤,並設置id
<
table id="table"></table>

 

$('#table').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'
    }]
});

也能夠經過url獲取數據ip

$('#table').bootstrapTable({
    url: 'data1.json',
    columns: [{
        field: 'id',    //與返回值的JSON數據的key值對應
        title: 'Item ID'  //列名
    }, {
        field: 'name',
        title: 'Item Name'
    }, {
        field: 'price',
        title: 'Item Price'
    }, ]
});
相關文章
相關標籤/搜索