jquery easy ui datagrid搜索不起作用

时间:2012-10-16 09:28:38

标签: jquery jquery-ui search datagrid

我这里有一点问题......

我有像这样的jquery easyui ......

function doSearch(){
            $('#dg').datagrid('load',{
                idCustomer: $('#idCustomer').val(),
                namaCustomer: $('#namaCustomer').val()
            });
        }

然后像这样的HTML ......

<table id="dg" title="Data Customer" class="easyui-datagrid" style="width:auto;height:500px;"  
        url="<?php echo $url;?>"  
        toolbar="#toolbar" 
        pageSize="20"
        rownumbers="true" fitColumns="true" singleSelect="true"
        pagination="true">  
    <thead>  
        <tr>  
            <th field="NoIDCust" width="50" sortable="true">ID Customer</th> 
            <th field="namaCustomer" width="50" sortable="true">Nama Customer</th>
            <th field="alamatCustomer" width="50" sortable="true">Alamat</th>
             <th field="telpCustomer" width="50" sortable="true">No Telepon</th>
             <th field="email" width="50" sortable="true">Email</th>
              <th field="area" width="50" sortable="true">Area</th>

        </tr>  
    </thead>  
</table>  
<div id="toolbar">  
    Nama : <input id="namaCustomer" style="line-height:16px;border:1px solid #ccc">  
    ID Customer :<input id="NoIDCust" style="line-height:16px;border:1px solid #ccc">  
    <a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()">Cari</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newCustomer()">Tambah Modul</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editCustomer()">Edit Modul</a>  
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeCustomer()">Hapus Modul</a>  
</div>

和一个像这样处理搜索功能的php文件......

$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
    $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
    $sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'idCustomer';  
    $order = isset($_POST['order']) ? strval($_POST['order']) : 'asc'; 

    $idCustomer = isset($_POST['idCustomer']) ? mysql_real_escape_string($_POST['idCustomer']) : '';
    $namaCustomer = isset($_POST['namaCustomer']) ? mysql_real_escape_string($_POST['namaCustomer']) : '';



    $offset = ($page-1)*$rows;

    $result = array();

    $where = "namaCustomer like '$namaCustomer%' and idCustomer like '$idCustomer%'";

    $rs = $db->query("select count(*) from customer where ". $where);
    $row = $rs->fetch(PDO::FETCH_NUM);
    $result["total"] = $row[0];

    $rs = $db->query("select * from customer where " . $where ." order by $sort $order limit $offset,$rows");

    $rows = array();
    while($row = $rs->fetch(PDO::FETCH_OBJ)){
    array_push($rows, $row);
    }
    $result["rows"] = $rows;

    echo json_encode($result);

问题是..我的搜索功能不起作用...它返回一个数据而没有被搜索框函数过滤..所以它意味着刚加载就像第一次加载...

任何人都可以帮助我吗?

非常感谢...

1 个答案:

答案 0 :(得分:2)

您只需重新加载网格即可。 doSearch函数应该是这样的:

    function doSearch(){
        $('#dg').datagrid('load',{
            idCustomer: $('#idCustomer').val(),
            namaCustomer: $('#namaCustomer').val()
        });
        $('#dg').datagrid('reload');
    }