zoukankan      html  css  js  c++  java
  • bootstraptable的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);
  • 相关阅读:
    详细描述一下 Elasticsearch 索引文档的过程 ?
    elasticsearch 索引数据多了怎么办,如何调优,部署 ?
    elasticsearch 了解多少,说说你们公司 es 的集群架构,索 引数据大小,分片有多少,以及一些调优手段 ?
    Dubbo 和 Dubbox 之间的区别?
    Dubbo 支持服务降级吗?
    Pipeline 有什么好处,为什么要用 pipeline?
    为什么redis 需要把所有数据放到内存中?
    你对线程优先级的理解是什么?
    在 java 中 wait 和 sleep 方法的不同?
    一个线程运行时发生异常会怎样?
  • 原文地址:https://www.cnblogs.com/wfy680/p/15544260.html
Copyright © 2011-2022 走看看