EasyUi---searchbox 条件查询

UI展示:
这里写图片描述

数据库:
这里写图片描述

前台UI参考代码:

<script type="text/javascript" charset="utf-8">
$(function(){
/***************************邮箱列表*********************************/  
    $('#single_process_table').datagrid({
        url:'./user/sGetProcess.php',
        border:false,
        fitColumns:false,
        singleSelect:true,
        pagination:true,
        pageSize:10,
        pageList:[10,15,20,25,100],
        columns:[[
            {field:'id',title:'序号'},
            {field:'name',title:'审批人'},
            {field:'department',title:'审批人所在部门',width:200},
            {field:'title',title:'流程主题',width:200}, 
            {field:'hi_number',title:'申请单编号'},
            {field:'used_time',title:'节点审批耗时'},
            {field:'detail',title:'邮箱状态'},
            {field:'page_url',title:'网址'}
        ]],
        onLoadError: function(){
            $.messager.alert('提示','没有符合条件的搜索结果!');
        }
    });
/***************************查询邮箱*********************************/    
    $('#single_search_process_box').searchbox({ 
        searcher:function(value,name){
            //当value为空的时候,搜索所有邮箱
            $('#single_process_table').datagrid('load', {
                search_name: name,    
                search_value: value
            });
        }, 
        menu:'#single_search_process_menu', 
        prompt:'Please Input Value'
    });

});    
</script>
<div class="it_model_top" style="height:auto;width:auto;padding:5px;border-bottom:1px solid #B4B4B4;">  
    <span style="margin-left: 10px;margin-right:10px;">
        <input id="single_search_process_box" style="width:250px;height:26px"></input>
        <div id="single_search_process_menu" fit="true">
            <div data-options="name:'name'">审批人</div>
            <div data-options="name:'title'">流程主题</div>
            <div data-options="name:'hi_number'">申请单编号</div>
            <div data-options="name:'detail'">邮箱状态</div>
        </div>
    </span> | 
    <span>更新时间:<?php echo getUpdateTime();?></span>
</div>

<table id="single_process_table"></table>

<?php 
function getUpdateTime(){
    require_once '../../class/c_mysql.class.php';
    $db = new c_mysql();
    $sql = "select system_time from running_remind limit 1";
    $db->connect();
    $db->query($sql);
    $db->close();
    $row = $db->fetch_row();
    $time = $row[0];
    return $time;
}
?>

后台参考代码:
sGetProcess.php

<?php 
//构造json对象,因为javascript处理类型为json
require_once '../../class/c_mysql.class.php';
if(isset($_POST['page']) && isset($_POST['rows']) && !isset($_POST['search_value']) && !isset($_POST['search_name'])){
    $page = $_POST['page'];
    $rows = $_POST['rows'];
    $limit_begain = ($page - 1) * $rows;
    $sql = "select name,department,title,hi_number,used_time,detail,page_url from running_remind order by `id` asc limit $limit_begain,$rows";
    $sql_count = "select count(*) from running_remind";
    //获取json格式数据
    get_json($sql,$sql_count);
}
if(isset($_REQUEST['search_name']) && isset($_REQUEST['search_value']) && isset($_REQUEST['page']) && isset($_REQUEST['rows'])){
    $page = $_POST['page'];
    $rows = $_POST['rows'];
    $limit_begain = ($page - 1) * $rows;
    $search_name = $_POST['search_name'];
    $search_vaule = $_POST['search_value'];
    if($search_vaule == ''){
        $sql = "select name,department,title,hi_number,used_time,detail,page_url from running_remind order by `id` asc limit $limit_begain,$rows";
        $sql_count = "select count(*) from running_remind";
    }elseif($search_name == 'hi_number'){
        $sql = "select name,department,title,hi_number,used_time,detail,page_url from running_remind where $search_name = '$search_vaule' order by `used_time` desc limit $limit_begain,$rows";
        $sql_count = "select count(*) from running_remind  where $search_name = '$search_vaule'";      
    }else{
        $sql = "select name,department,title,hi_number,used_time,detail,page_url from running_remind where $search_name like '%$search_vaule%' order by `used_time` desc limit $limit_begain,$rows";
        $sql_count = "select count(*) from running_remind  where $search_name like '%$search_vaule%'";

    }
    //获取json格式数据
    get_json($sql,$sql_count);
}

function get_json($sql,$sql_count){
    $db = new c_mysql();   
    $db->connect();
    $db->query($sql);
    $db->close();
    $count = 1;
    while($row = $db->fetch_array()){
        $row['id'] = $count;
        $row['used_time'] = number_format($row['used_time'] / 3600,2,'.','').'小时';
        $row['page_url'] = "<a target='_blank' href='$row[page_url]'>进入网址</a>";
        $row['department'] = explode('-',$row['department']);
        $row['department'] = $row['department'][0];
        $grid_data[] = $row;
        $count++;
    }
    //计算总数  
    $db->connect();
    $db->query($sql_count);
    $db->close();
    $row = $db->fetch_row();
    $total = $row[0];
    //合并json
    $json = new json_data();
    $json->total = $total;
    $json->rows = $grid_data;
    echo json_encode($json);
}

class json_data{
    public $total = 10;
    public $rows = array();
}
?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值