Home > Web Front-end > Bootstrap Tutorial > How to bind data in bootstrap table

How to bind data in bootstrap table

(*-*)浩
Release: 2019-07-11 09:27:11
Original
3933 people have browsed it

支持三种方式bootstrap table绑定数据:1.html格式数据(即静态数据);2.JavaScript传递数据;3.数据属性变量动态获取。

How to bind data in bootstrap table

静态表格:data-toggle="table"(推荐学习:Bootstrap视频教程

<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>
Copy after login

JavaScript方式

<table id="table"></table>
<!--定义一个表格,无需设置表头,统一在JS中初始化,灵活度较高(梁新建议)-->
<script>
$('#table').bootstrapTable({
  url: 'data1.json',
  pagination: true,
  search: true
  columns: [{
    field: 'id',
    title: 'Item ID'
  }, {
    field: 'name',
    title: 'Item Name'
  }, {
    field: 'price',
    title: 'Item Price'
  }, ]
})
</script>
Copy after login

数据属性变量动态获取

<table
  data-toggle="table"
  data-url="data1.json"
  data-pagination="true"
  data-search="true">
  <thead>
    <tr>
      <th data-sortable="true" data-field="id">Item ID</th>
      <th data-field="name">Item Name</th>
      <th data-field="price">Item Price</th>
    </tr>
  </thead>
</table>
Copy after login

更多Bootstrap相关技术文章,请访问Bootstrap教程栏目进行学习!

The above is the detailed content of How to bind data in bootstrap table. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template