首页 > bootstrap table 方法 > bootstrap table resetSearch重置搜索框

bootstrap table resetSearch重置搜索框

如果你开启了搜索框,可以通过resetSearch重置搜索框。

resetSearch方法

参数名称
text设置搜索框的值,也可以不设置

代码例子

//重置搜索框为空
$('#table').bootstrapTable('resetSearch');
//重置搜索框字符串为1000
$('#table').bootstrapTable('resetSearch');

在线试一试 

完整例子

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
   <script src="http://www.itxst.com/package/jquery-3.3.1/jquery.js"></script>
    <link href="http://www.itxst.com/package/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet" />
    <link href="http://www.itxst.com/package/bootstrap-table-1.15.3/bootstrap-table.css" rel="stylesheet" />
    <script src="http://www.itxst.com/package/bootstrap-table-1.15.3/bootstrap-table.js"></script>  
    <title>Bootstrap Table resetSearch在线例子</title>
    <style>
        .table-demo {
            width: 80%;
            margin: 30px 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 id="toolbar">
  <button   class="btn btn-secondary" onclick="act()">重置搜索框为空</button>
    <button   class="btn btn-secondary" onclick="act2()">重置搜索框为1000</button>
</div>
    <div class="table-demo">
        <table id="table"></table>
    </div>
    <script>
        //设置列
        var columns = [
          {checkbox:true},{
            field: 'Id',
            title: 'ID'
        }, {
            field: 'Food',
            title: '食物'
        }, {
            field: 'WW',
            title: '销量'
        }];
 
        //bootstrap table初始化数据
        $('#table').bootstrapTable({
            toolbar:"#toolbar", 
            search:"true", 
            searchText:"2", 
            columns: columns,
            data: getData(),
            classes: "table table-bordered table-striped table-sm", //设置表格样式
           height:500,
          
        });


        function getData()
        {
            var data = [];


            for (var i = 0; i < 500; i++)
            {
                var item = {
                    Id: i,
                    Food: '苹果',
                    WW: i+1000
                };


                data.push(item);
            };


            return data;


        }
      
     function act()
      {
        $('#table').bootstrapTable('resetSearch')
      }
      function act2()
      {
        $('#table').bootstrapTable('resetSearch','1000')
      }


    </script>
</body>
</html>