bootstrap table 事件

bootstrap table onPostBody表格渲染前事件

onPostBody是在bootstrap table表格的body渲染之后执行的事件,该事件参数返回需要渲染的data数据。

onPostBody事件

返回参数如下。

参数名称 说明
data 需要渲染的data数据

onPostBody事件绑定方式一

$('#table').bootstrapTable({
   columns: columns,
   data: data, 
    onPostBody:function(data)
    { 
     alert(JSON.stringify(data));
    }
});

onPostBody事件绑定方式二

注意:pre-body.bs.table方式需要的加载数据之前绑定,否则第一次加载数据进行渲染将不会生效

$('#table').on('post-body.bs.table', function (e,data){
   alert(JSON.stringify(data));
});

完整代码

<!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 onPostBody表格渲染后事件例子</title>
    <style>
        .table-demo {
            width: 80%;
            margin: 60px auto 0px auto;
        }
        .fixed-table-header {
            border-right: solid 1px #ddd;
            border-top: solid 1px #ddd;
        }
         .fixed-table-header table {
                border-top: solid 0px #ddd !important;
                margin-top: -1px;
         }
    </style>
</head>
<body>
    <div class="table-demo">
        <table id="table"></table>
    </div>
    <script>
        //设置需要显示的列
        var columns = [  {
            field: 'Id',
            title: '序号'
        }, {
            field: 'Model',
            title: '型号'
        }, {
            field: 'Num',
            title: '库存'
        }];
 
      
        //bootstrap table初始化数据
        $('#table').bootstrapTable({
            columns: columns,
            data: getData(),
            classes: "table table-bordered table-striped table-sm ", //设置表格样式
            height: 500,
            onPostBody:function(data)
           { 
            alert(JSON.stringify(data));
             }
        });

        function getData() {
            var data = [];
            for (var i = 0; i < 50; i++) {
                var item = {
                    Id: i,
                    Model: 'P0' + i,
                    Num: i + 5
                };
                data.push(item);
            };
            return data;
        }
    </script>
</body>
</html>

在线试一试  

Catalog
bootstrap table事件 bootstrap table方法 bootstrap table配置 bootstrap table下载 onRefreshOptions配置改变事件 onClickRow点击行事件 onDblClickRow双击行事件 onClickCell点击单元格事件 onDblClickCell双击单元格事件 onSort列排序事件 onCheck选中行事件 onUncheck选中行事件 onCheckAll全选事件 onUncheckAll取消全选事件 onLoadSuccess数据加载成功事件 onLoadError数据加载失败事件 onColumnSwitch选择列事件 onPageChange分页事件 onSearch搜索事件 onToggle切换视图事件 onPreBody表格渲染前事件 onPostHeader表头渲染事件 onExpandRow点击展开事件 onPostBody表格渲染前事件 onCollapseRow收起事件 onResetView视图切换事件 onRefresh刷新事件 onScrollBody滚动事件