layui 数据表格实现关键字搜索

参考:https://blog.csdn.net/weixin_41606652/article/details/84204334

html部分:

搜索:

js部分:

//搜索功能实现
  var $ = layui.$, active = {
    reload: function(){
      var demoReload = $('#demoReload');
	  
	  console.log("demoReload.val:" + demoReload.val());
      
      //执行重载
      table.reload('testReload', {
	    //url:'/index.php/Admin/Page/selectByPage',
		//method:'get',
        page: {
          curr: 1 //重新从第 1 页开始
        }
        ,where: {
          page_name: demoReload.val()  //搜索关键词
        }
      }, 'data');
    }
  };
  
  //执行关键字搜索的函数
  $('.demoTable .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });

    php后台:

  

// 获取单页信息信息
  	public function selectByPage() {
        header('content-type:application/json');
		
		$page_name = $_GET["page_name"]!='' ? $_GET["page_name"] : '';		
		$page = $_GET["page"]!='' ? $_GET["page"] : 1;		
		$limit = $_GET["limit"]!='' ? $_GET["limit"] : 10;
        
        $mode = M("page"); // 实例化对象		
		
		$where = "page_name like '%".$page_name."%'";
		$list = $mode->where($where)->order('create_time desc')->limit((($page-1)*$limit).','.$limit)->select();	
		
		$count = $mode->count(); //总记录数		
      
        $obj->code = 0;
        $obj->msg = 'OK';
        $obj->data  = $list;
        $obj->count = $count;
        echo json_encode($obj);
    } 

    

你可能感兴趣的:(layui,php,layui数据表格,关键字搜索,筛选条件)