<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: navigator search does not refresh grid</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/navigator-search-does-not-refresh-grid</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/help/navigator-search-does-not-refresh-grid/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>fezonhead on navigator search does not refresh grid</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/navigator-search-does-not-refresh-grid#p21103</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/navigator-search-does-not-refresh-grid#p21103</guid>
        	        	<description><![CDATA[<p>I&#39;ve written a very basic ajax module to test out the jqGrid navigator. ADD, DELETE and UPDATE work fine but when I try SEARCH the grid does not refresh and when I quit out of the search modal and try an EDIT, DELETE or UPDATE the changes are made to the database but not reflected on the grid. Also the record navigation does not work. I can only get these working again if I press the REFRESH button.</p>
<p>I also have the same problem with the SEARCH function on the downloadable sample files for NAVIGATOR.</p>
<p>The database I&#39;m using is a simple mySQL with a table called MINGRID with fields id, name, number being integer, text, integer.</p>
<p>Here&#39;s my HTML file [mingrid.html]:</p>
<p>&#60;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&#62;</p>
<p>&#60;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&#62;</p>
<p>&#60;head&#62;</p>
<p>&#60;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&#62;</p>
<p>&#60;title&#62;My First Grid&#60;/title&#62;</p>
</p>
<p>&#60;link rel="stylesheet" type="text/css" media="screen" href="css/overcast/jquery-ui-1.8.6.custom.css" /&#62;</p>
<p>&#60;link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" /&#62;</p>
<p>&#60;link rel="stylesheet" type="text/css" media="screen" href="css/jqui.css" /&#62;</p>
<p>&#60;link rel="stylesheet" type="text/css" media="screen" href="css/main.css" /&#62;</p>
</p>
<p>&#60;style&#62; &#60;!--reduce font size to compensate jqg style--&#62;</p>
<p>html, body {</p>
<p>margin: 0;</p>
<p>padding: 0;</p>
<p>font-size: 75%;</p>
<p>}</p>
<p>&#60;/style&#62;</p>
</p>
<p>&#60;!--Scripts--&#62;</p>
<p>&#60;script src="js/jquery.js" type="text/javascript"&#62;&#60;/script&#62;</p>
<p>&#60;script src="js/jqgrid - src/jquery.searchFilter.js" type="text/javascript"&#62;&#60;/script&#62;</p>
<p>&#60;script src="js/i18n/jqgrid-locale.js" type="text/javascript"&#62;&#60;/script&#62;</p>
<p>&#60;script src="js/jquery-ui-1.8.6.custom.min.js" type="text/javascript"&#62;&#60;/script&#62;</p>
<p>&#60;script src="js/jquery.jqgrid.min.js" type="text/javascript"&#62;&#60;/script&#62;</p>
</p>
<p>&#60;script type="text/javascript"&#62;</p>
<p>$(document).ready(function(){</p>
<p>$("#ngrid").jqGrid({</p>
<p>url:&#39;ajaxread.php&#39;,</p>
<p>datatype: &#39;xml&#39;,</p>
<p>mtype: &#39;GET&#39;,</p>
<p>colNames:[&#39;Id&#39;,&#39;Name&#39;, &#39;Number&#39;],</p>
<p>colModel :[</p>
<p>{name:&#39;id&#39;, index:&#39;id&#39;, width:55, search: false},</p>
<p>{name:&#39;name&#39;, index:&#39;name&#39;, width:90, editable: true},</p>
<p>{name:&#39;number&#39;, index:&#39;number&#39;, width:80, align:&#39;right&#39;, editable: true}</p>
<p>],</p>
<p>pager: &#39;#pager&#39;,</p>
<p>height: 300,</p>
<p>width: 600,</p>
<p>rowNum:20,</p>
<p>rowList:[10,20,40,100],</p>
<p>sortname: &#39;name&#39;,</p>
<p>sortorder: &#39;desc&#39;,</p>
<p>viewrecords: true,</p>
<p>caption: &#39;MinGrid&#39;,</p>
<p>editurl: &#39;ajaxcud.php&#39;</p>
<p>}).navGrid(&#39;#pager&#39;);</p>
<p>});</p>
<p>&#60;/script&#62;</p>
<p>&#60;/head&#62;</p>
<p>&#60;body&#62;</p>
<p>&#60;div id="wrapper"&#62;</p>
<p>&#60;h1&#62;Testing sandbox&#60;/h1&#62;</p>
<p>&#60;p&#62;&#38;nbsp;&#60;/p&#62;</p>
<p>&#60;table id="ngrid"&#62;&#60;/table&#62;</p>
<p>&#60;div id="pager"&#62;&#60;/div&#62;</p>
<p>&#60;/div&#62;</p>
<p>&#60;/body&#62;</p>
<p>&#60;/html&#62;</p>
<p>&#160;_____________________________________________________________</p>
<p>and here&#39;s my PHP file for the standard AJAX call.... (ajaxread.php)...</p>
<p>&#60;?php</p>
<p>require_once(&#39;Connections/dbfn.php&#39;); // dbfn.php also has logcall function to record info to a log file for debugging</p>
<p>// Get basic variables</p>
<p>$page = $_REQUEST[&#39;page&#39;];</p>
<p>$limit = $_REQUEST[&#39;rows&#39;];</p>
<p>$sidx = $_REQUEST[&#39;sidx&#39;];</p>
<p>$sord = $_REQUEST[&#39;sord&#39;];</p>
<p>// if no index is passed then use the first column</p>
<p>if(!$sidx) $sidx =1;</p>
<p>// Set the COUNT SQL query depending on whether it&#39;s a search call or not</p>
<p>$search=$_REQUEST[&#39;_search&#39;];</p>
<p>if ($search == &#39;true&#39;) {</p>
<p>$searchstr=$_REQUEST[&#39;searchString&#39;];</p>
<p>$searchfield=$_REQUEST[&#39;searchField&#39;];</p>
<p>$searchop=$_REQUEST[&#39;searchOper&#39;];</p>
<p>switch ($searchop) {</p>
<p>case eq:</p>
<p>$modop = &#39;=&#39;;</p>
<p>break;</p>
<p>case le:</p>
<p>$modop = &#39;&#60;=&#39;;</p>
<p>break;</p>
<p>case ne:</p>
<p>$modop = &#39;&#60;&#62;&#39;;</p>
<p>break;</p>
<p>case lt:</p>
<p>$modop = &#39;&#60;&#39;;</p>
<p>break;</p>
<p>case gt:</p>
<p>$modop = &#39;&#62;&#39;;</p>
<p>break;</p>
<p>case ge:</p>
<p>$modop = &#39;&#62;=&#39;;</p>
<p>break;</p>
<p>case bw:</p>
<p>$modop = &#39;LIKE&#39;;</p>
<p>break;</p>
<p>case bn:</p>
<p>$modop = &#39;NOT LIKE&#39;;</p>
<p>break;</p>
<p>case in:</p>
<p>$modop = &#39;LIKE&#39;;</p>
<p>break;</p>
<p>case ni:</p>
<p>$modop = &#39;NOT LIKE&#39;;</p>
<p>break;</p>
<p>case ew:</p>
<p>$modop = &#39;LIKE&#39;;</p>
<p>break;</p>
<p>case en:</p>
<p>$modop = &#39;NOT LIKE&#39;;</p>
<p>break;</p>
<p>case cn:</p>
<p>$modop = &#39;LIKE&#39;;</p>
<p>break;</p>
<p>case nc:</p>
<p>$modop = &#39;NOT LIKE&#39;;</p>
<p>break;</p>
<p>default:</p>
<p>$modop = &#39;LIKE&#39;;</p>
<p>}</p>
<p>$sqlcount=sprintf("SELECT COUNT(*) AS count FROM mingrid WHERE %s %s %s", $searchfield, $modop, $searchstr);</p>
<p>}</p>
<p>else {</p>
<p>$sqlcount="SELECT COUNT(*) AS count FROM mingrid";</p>
<p>}</p>
<p>logcall(&#39;count string - &#39;.$sqlcount);</p>
<p>// calculate the number of rows for the query. We need this for paging the result</p>
<p>$result = mysql_query($sqlcount);</p>
<p>$row = mysql_fetch_array($result,MYSQL_ASSOC);</p>
<p>$count = $row[&#39;count&#39;];</p>
<p>// calculate the total pages for the query</p>
<p>if( $count &#62; 0 &#38;&#38; $limit &#62; 0) {</p>
<p>$total_pages = ceil($count/$limit);</p>
<p>} else {</p>
<p>$total_pages = 0;</p>
<p>}</p>
</p>
<p>logcall(&#39;Row count - &#39;.$count.&#39; Total pages - &#39;.$total_pages);</p>
</p>
<p>// check start and limit are within bounds</p>
<p>// set the requested page to total page</p>
<p>if ($page &#62; $total_pages) $page=$total_pages;</p>
<p>// calculate the starting position of the rows</p>
<p>$start = $limit*$page - $limit;</p>
<p>// if for some reasons start position is negative set it to 0</p>
<p>// typical case is that the user type 0 for the requested page</p>
<p>if($start &#60;0) $start = 0;</p>
<p>// set the SELECT SQL query depending on whether it&#39;s a search call or not</p>
<p>if ($search == &#39;true&#39;) {</p>
<p>$sqlcall="SELECT id, name, number FROM mingrid WHERE $searchfield $modop $searchstr ORDER BY $sidx $sord LIMIT $start , $limit";</p>
<p>}</p>
<p>else {</p>
<p>$sqlcall="SELECT id, name, number FROM mingrid ORDER BY $sidx $sord LIMIT $start , $limit";</p>
<p>}</p>
<p>logcall(&#39;select query - &#39;.$sqlcall);</p>
<p>// do the SQL query</p>
<p>$result = mysql_query($sqlcall) or die("Couldn&#39;t execute query.".mysql_error());</p>
<p>logcall(&#39;Result of query - &#39;.$result);</p>
<p>// Set the header information.</p>
<p>header("Content-type: text/xml;charset=utf-8");</p>
<p>$s = "&#60;?xml version=&#39;1.0&#39; encoding=&#39;utf-8&#39;?&#62;";</p>
<p>$s .=  "&#60;rows&#62;";</p>
<p>$s .= "&#60;page&#62;".$page."&#60;/page&#62;";</p>
<p>$s .= "&#60;total&#62;".$total_pages."&#60;/total&#62;";</p>
<p>$s .= "&#60;records&#62;".$count."&#60;/records&#62;";</p>
<p>// set up the XML</p>
<p>while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {</p>
<p>$s .= "&#60;row id=&#39;". $row[&#39;id&#39;]."&#39;&#62;";</p>
<p>$s .= "&#60;cell&#62;". $row[&#39;id&#39;]."&#60;/cell&#62;";</p>
<p>$s .= "&#60;cell&#62;". $row[&#39;name&#39;]."&#60;/cell&#62;";</p>
<p>$s .= "&#60;cell&#62;". $row[&#39;number&#39;]."&#60;/cell&#62;";</p>
<p>$s .= "&#60;/row&#62;";</p>
<p>}</p>
<p>$s .= "&#60;/rows&#62;";</p>
<p>// record and write the XML</p>
<p>logcall("Returned XML:\n ".$s);</p>
<p>echo $s;</p>
<p>?&#62;</p>
<p>____________________________________________________</p>
<p>...here&#39;s the PHP file for the UPDATE, DELETE and ADD function calls... (ajaxcud.php)...</p>
<p>&#60;?php</p>
<p>require_once(&#39;Connections/dbfn.php&#39;);</p>
<p>// get the parameters</p>
<p>$id=$_REQUEST[&#39;id&#39;];</p>
<p>$oper=$_REQUEST[&#39;oper&#39;];</p>
<p>$name=$_REQUEST[&#39;name&#39;];</p>
<p>$number=$_REQUEST[&#39;number&#39;];</p>
</p>
<p>// Set the SQL script as per the oper request</p>
<p>switch ($oper){</p>
<p>case edit:</p>
<p>$sqlcmd=sprintf("UPDATE mingrid SET %s=&#39;%s&#39;, %s=&#39;%s&#39; WHERE %s=%u",</p>
<p>"name",$name,</p>
<p>"number",$number,</p>
<p>"id",$id);</p>
<p>break;</p>
<p>case add:</p>
<p>$sqlcmd=sprintf("INSERT INTO mingrid (%s, %s) VALUES (&#39;%s&#39;, &#39;%s&#39;)",</p>
<p>"name", "number",</p>
<p>$name, $number);</p>
<p>break;</p>
<p>case del:</p>
<p>$sqlcmd=sprintf("DELETE FROM mingrid WHERE %s=%u",</p>
<p>"id",$id);</p>
<p>break;</p>
<p>default:</p>
<p>}</p>
<p>// record query</p>
<p>logcall(&#39;ajaxcud executed SQL - &#39;.$sqlcmd);</p>
<p>// execute query</p>
<p>mysql_query($sqlcmd) or die(mysql_error());</p>
<p>?&#62;</p>
<p>________________________________________________</p>
<p>and (finally) my connections PHP (dbfn.php)...</p>
<p>&#60;?php</p>
<p>function logcall($qs){</p>
<p>//write to the log file</p>
<p>$filename = "log.txt";</p>
<p>$fd = fopen ($filename , "r");</p>
<p>$fstring = file_get_contents($filename);</p>
<p>fclose($fd);</p>
<p>$fd = fopen ($filename , "w");</p>
<p>$fstring .= "\n** ";</p>
<p>$fstring .= $qs;</p>
<p>fwrite ($fd , $fstring);</p>
<p>fclose($fd);</p>
<p>}</p>
</p>
<p>$dbhost = &#39;localhost&#39;;</p>
<p>$dbuser = &#39;root&#39;;</p>
<p>$dbpassword = &#39;&#39;;</p>
<p>$database = &#39;mingrid&#39;;</p>
<p>$db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error());</p>
<p>mysql_select_db($database) or die("Error connecting to db.");</p>
<p>?&#62;</p>
<p>_________________________________________________</p>
<p>As you can see, I am logging the activity of the PHP calls and that all seems to be working fine.&#160;</p>
<p>I would very much appreciate any advice as I&#39;ve been working hard on this problem for several days now and it is driving me wild. I can&#39;t seem to find anyone else with the same issue so it is obviously me making some simple error.</p>
</p>
<p>Thanks in advance for your help.</p></p>
]]></description>
        	        	<pubDate>Fri, 03 Dec 2010 13:19:17 +0200</pubDate>
        </item>
</channel>
</rss>