Hi, I don't know what I miss but my search doesn't work, can you tell me what I make wrong please?
Here is all my scripts:
index.php<?php
include '../header.php';
include '../conn.php';
?>
<!-- page content -->
<link rel="stylesheet" type="text/css" href="../crud_script/easyui.css">
<link rel="stylesheet" type="text/css" href="../crud_script/icon.css">
<link rel="stylesheet" type="text/css" href="../crud_script/color.css">
<link rel="stylesheet" type="text/css" href="../crud_script/demo.css">
<!--jQuery.noConflict(true);-->
<!--<script type="text/javascript" src="jquery-1.6.min.js"></script>-->
<script type="text/javascript" src="../crud_script/jquery.easyui.min.js"></script>
<table id="dg" class="easyui-datagrid" style="width:100%;height:auto"
url="get_users.php"
toolbar="#toolbar" pagination="true"
rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th field="firstname" width="50" sortable="true">First Name</th>
<th field="lastname" width="50">Last Name</th>
<th field="phone" width="50">Phone</th>
<th field="email" width="50">Email</th>
</tr>
</thead>
</table>
</center>
<div id="toolbar">
[b][color=red]<input id="search" style="line-height:18px;border:1px solid #ccc"/>
<a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()">Search</a>[/color][/b]
</div>
<script type="text/javascript">
//...
function doSearch() {
var c = $('#search').val()
alert(c);
$('#dg').datagrid('load', {
search: $('#search').val()
});
}
</script>
<?php
include '../footer.php';
And my get_users.php:
<?php
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$search = isset($_POST['search']) ? mysql_real_escape_string($_POST['search']) : '';
$sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'firstname';
$order = isset($_POST['order']) ? strval($_POST['order']) : 'asc';
$offset = ($page - 1) * $rows;
//$search ='nse';
$result = array();
$where = "firstname like '%".$search."%'";
include '../conn.php';
$stmt1 = $db->prepare("select count(*) AS count from tbl_staff where " . $where);
$stmt1->execute(array());
$rowcount = $stmt1->rowCount();
if ($rowcount > 0)// ...
{
$rows_ = $stmt1->fetch(PDO::FETCH_ASSOC);
$result["total"] = $rows_['count'];
}
//-------------
$stmt12 = $db->prepare("select * from tbl_staff where " . $where . " order by $sort $order limit " . $offset . "," . $rows . "");
$stmt12->execute(array());
$rowcount = $stmt12->rowCount();
if ($rowcount > 0)// ...
{
$items = array();
WHILE ($rows = $stmt12->fetch(PDO::FETCH_ASSOC)) {
array_push($items, $rows);
}
$result["rows"] = $items;
}
echo json_encode($result);
?>
How to make the search by keyup and for data already loaded without requesting again the server (I followed the post:
http://www.jeasyui.com/forum/index.php?topic=3420.0 and the documentation but no result).
Thanks