其他分享
首页 > 其他分享> > bootstrap-table的queryParams使用

bootstrap-table的queryParams使用

作者:互联网

queryParams是bootstrap-table的一个属性功能。

前端代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>第二个</title>
    .......
</head>
<body>
    <input type="text" id="test" placeholder="输入用户id" >
    <input type="text" id="test1" placeholder="输入用户名" >
    <input type="button"  value="找它" id="name">
    <table id="table" data-toggle="table"
        data-url="<?php echo base_url('work2/page');?>"
        data-pagination="true"
        data-side-pagination="server"
      data-query-params="queryParams" >
    <thead>
      <tr>
        <th data-field="uid" data-filter-control="input">ID</th>
        <th data-field="username">用户名</th>
        <th data-field="password">用户密码</th>
      </tr>
     </thead>
    </table>

    <script>
      function queryParams(params) {
        var uid = $("#test").val();                          //获取文本框的值
        var name = $("#test1").val();                        //获取文本框的值
        params.search1 = uid;
        params.search2 = name;
        return params;
      }

       $('#name').click(function () {
               $('#table').bootstrapTable('refresh')
         })
    </script>

</body>
</html>

 后端代码如下php:

前端传入后台的是一个对象,前后台一般都以JSON字符串传递,后台只要根据关键字名称取值。

        $search = $this->input->get('search2');                             //这个是查用户名
            $search1 = $this->input->get('search1');                            //这个是查uid

            if(empty($search) && empty($search1)){
                //两个空则输出全部数据
                $rows = $this->db->limit($limit,$offset)->get('user1')->result();
                $count = $this->db->count_all('user1');
            }else if(empty($search) && $search1 != " " ){
                //用户名空,查uid
                $rows = $this->db->like('uid',$search1)->limit($limit,$offset)->get('user1')->result();
                $count = $this->db->like('uid',$search1)->count_all_results('user1');
            }
            else if(empty($search1) && $search != " " ){
                //uid空,查用户名
                $rows = $this->db->like('username',$search)->limit($limit,$offset)->get('user1')->result();
                $count = $this->db->like('username',$search)->count_all_results('user1');
            }else{
                //一起查
                $rows = $this->db->like('uid',$search1)->like('username',$search)->get('user1')->result();
                $count = $this->db->like('uid',$search1)->like('username',$search)->count_all_results('user1');
            }
            $data = array(
                'total'=>$count,
                'rows'=>$rows
            );
            echo json_encode($data);

 

标签:count,search,uid,user1,bootstrap,db,table,search1,queryParams
来源: https://www.cnblogs.com/wfy680/p/15544260.html