Bootstrap Table学习笔记

资料: 官网   2017.7.10

入门实例

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap Table</title>
    <link href="Styles/css/bootstrap.min.css" rel="stylesheet" />
    <link href="Styles/css/bootstrap-table.min.css" rel="stylesheet" />
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <script src="Scripts/Core/jquery-1.12.4.min.js" type="text/javascript"></script>
    <script src="Scripts/Core/bootstrap.min.js"></script>
    <script src="Scripts/Extensions/bootstrap-table.js"></script>
    <script src="Scripts/Extensions/bootstrap-table-locale-all.js"></script>
    <script src="Scripts/Main.js"></script>
</head>
<body>
    <table id="table"></table>
</body>
</html

通过JavaScript激活Bootstrap Table, coding在Main.js内

$(function () {
    $('#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'
        }]
    })
})

内置方法:bootstrapTable(), 内置属性: columns, data  请参看Document

PS:阅读Bootstrap Table Document

上面的HTML <table id="table"></table> ,Bootstrap Table会将其绚烂成table

和bootstrap Table Document的对应关系,

表示bootstrapTable插件中的classes会被转成Attribute(属性),字面值data-classes, 关于data-[xxx]语法,请参考bootstrap的data-api用法.

获取当前行的数据

tableData.columnDefs = [
	{
		"render": function (data, type, row, meta) {
			var tmp = '<a onclick="editStaff(\'' + meta.row +'\')" title="编辑" ><i class="fa fa-edit" ></i></a>';
			return tmp;
		},
		"targets": -1
	}
];
function editStaff(rowIndex) {
    //var x1 = table.rows({ selected: true }).data();
    //var pageData = table.rows({ page: 'current' }).data();
    var currentRowData = table.rows(rowIndex, { order: 'index' }).data();//table 是 DataTable 对象,核心语法, DataTable 选择语法,参考官方API

    $('#new_staff_no').val(currentRowData[0].staff_no);

 

  

posted @ 2017-07-10 14:58  轴轴  阅读(312)  评论(0编辑  收藏  举报