bootstrap table 事件

bootstrap table onToggle切换视图事件

当bootstrap table开启搜索输入框,用户输入关键词时的事件,返回text关键词字符串,需要把showToggle属性设置为true才生效。

onToggle 事件

返回参数如下。

参数名称说明
cardView卡片状态 true卡片视图 false表格视图

绑定onToggle事件方法一

$('#table').bootstrapTable({
     columns: columns,
     data: data,
     cardView :true, 
     showToggle:true, //1,注意这里必须设置true,onToggle事件才会生效
     onToggle:function(cardView)
      { 
    alert(JSON.stringify(cardView));
}

绑定onToggle事件方法二

$('#table').on('toggle.bs.table', function (e,cardView){
   alert(JSON.stringify(cardView));
});

完整代码

<!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>
       <link href="https://www.itxst.com/package/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
    <title>bootstrap table onToggle切换视图事件例子</title>
    <style>
        .table-demo {
            width: 60%;
            margin: 60px auto 0px auto;
        }
    </style>
</head>
<body>
    <div class="table-demo">
        <table id="table"></table>
    </div>
    <script>
        //设置需要显示的列
        var columns = [{
            field: 'Id',
            title: 'ID'
        }, {
            field: 'ProductName',
            title: '名称'
        }, {
            field: 'StockNum',
            title: '数量'
        }];


        //需要显示的数据
        var data = [{
            Id: 1,
            ProductName: '甘蔗',
            StockNum: '12'
        }, {
            Id: 2,
            ProductName: '西瓜',
            StockNum: '30'
        }];
        //bootstrap table初始化
        $('#table').bootstrapTable({
            columns: columns,
            data: data,
            cardView :true, 
            showToggle:true,
            onToggle:function(cardView)
           { 
             alert(JSON.stringify(cardView));
           }
        });
    
    </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滚动事件