<?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: Search with select method and data from a xml file.</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/search-with-select-method-and-data-from-a-xml-file</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/search-with-select-method-and-data-from-a-xml-file/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>netpumber on Search with select method and data from a xml file.</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/search-with-select-method-and-data-from-a-xml-file#p25050</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/search-with-select-method-and-data-from-a-xml-file#p25050</guid>
        	        	<description><![CDATA[</p>
<p>Hello.. I was reading the jqgrid documentation today and i have create a simple table that gets its data from a mysql database with the help of PHP.</p>
</p>
<p>Here is the code :</p>
</p>
<p><input type='button' class='sfcodeselect' name='sfselectit8523' value='Select Code' data-codeid='sfcode8523' /></p>
<div class='sfcode' id='sfcode8523'>
<p>&#160;index.html</p>
<p>&#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Strict//EN&#34; &#34;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&#34;&#038;gt" rel="nofollow" target="_blank"><a href="http://www.w3.org/TR/xhtml1/DT" rel="nofollow">http://www.w3.org/TR/xhtml1/DT</a>.....t;&#038;gt</a>;<br />&#60;html xmlns=&#34;<a href="http://www.w3.org/1999/xhtml&#038;quot" rel="nofollow" target="_blank">http://www.w3.org/1999/xhtml&#038;quot</a>; xml:lang=&#34;en&#34; lang=&#34;en&#34;&#62;<br />&#60;head&#62;<br />&#60;meta http-equiv=&#34;Content-Type&#34; content=&#34;text/html; charset=utf-8&#34; /&#62;<br />&#60;title&#62;My First Grid&#60;/title&#62;<br />&#160;<br />&#60;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; media=&#34;screen&#34; href=&#34;css/smoothness/jquery-ui-1.8.16.custom.css&#34; /&#62;<br />&#60;link rel=&#34;stylesheet&#34; type=&#34;text/css&#34; media=&#34;screen&#34; href=&#34;css/ui.jqgrid.css&#34; /&#62;<br />&#160;<br />&#60;script src=&#34;js/jquery-1.5.2.min.js&#34; type=&#34;text/javascript&#34;&#62;&#60;/script&#62;<br />&#60;script src=&#34;js/i18n/grid.locale-en.js&#34; type=&#34;text/javascript&#34;&#62;&#60;/script&#62;<br />&#60;script type=&#34;text/javascript&#34; src=&#34;js/jquery.jqGrid.min.js&#34;&#62;&#60;/script&#62;</p>
<p>&#60;style&#62;<br />html, body {<br />&#160;&#160;&#160; margin: 0;<br />&#160;&#160;&#160; padding: 0;<br />&#160;&#160;&#160; font-size: 75%;<br />}<br />&#60;/style&#62;</p>
<p>&#60;script type=&#34;text/javascript&#34;&#62;</p>
<p>$(function(){ <br />&#160;&#160; &#160;<br />&#160; mygrid = $(&#34;#list&#34;);<br />&#160;&#160; &#160;<br />&#160; mygrid.jqGrid({<br />&#160;&#160;&#160; url:&#39;example.php&#39;,<br />&#160;&#160;&#160; datatype: &#39;xml&#39;,<br />&#160;&#160;&#160; mtype: &#39;GET&#39;,<br />&#160;&#160;&#160; colNames:[&#39;Inv No&#39;,&#39;Date&#39;, &#39;Amount&#39;,&#39;Tax&#39;,&#39;Total&#39;,&#39;Notes&#39;],<br />&#160;&#160;&#160; colModel :[ <br />&#160;&#160;&#160;&#160;&#160; {name:&#39;invid&#39;, index:&#39;invid&#39;, width:55}, <br />&#160;&#160;&#160;&#160;&#160; {name:&#39;invdate&#39;, index:&#39;invdate&#39;, width:90}, <br />&#160;&#160;&#160;&#160;&#160; {name:&#39;amount&#39;, index:&#39;amount&#39;, width:80, align:&#39;right&#39;, edittype:&#39;select&#39;, search:true , stype:&#39;select&#39;, <br />&#160;&#160; &#160;&#160; searchoptions:{value:&#39;:All;8:8.00;6:6.00&#39;}}, <br />&#160;&#160;&#160;&#160;&#160; {name:&#39;tax&#39;, index:&#39;tax&#39;, width:80, align:&#39;right&#39;}, <br />&#160;&#160;&#160;&#160;&#160; {name:&#39;total&#39;, index:&#39;total&#39;, width:80, align:&#39;right&#39;, sortable:true}, <br />&#160;&#160;&#160;&#160;&#160; {name:&#39;note&#39;, index:&#39;note&#39;, width:150, sortable:false, align:&#39;center&#39;} <br />&#160;&#160;&#160; ],<br />&#160;&#160;&#160; pager: &#39;#pager&#39;,<br />&#160;&#160;&#160; rowNum:10,<br />&#160;&#160;&#160; rowList:[10,20,30],<br />&#160;&#160;&#160; sortname: &#39;tax&#39;,<br />&#160;&#160;&#160; sortorder: &#39;desc&#39;,<br />&#160;&#160;&#160; viewrecords: true,<br />&#160;&#160;&#160; gridview: true,<br />&#160;&#160;&#160; caption: &#39;My first grid&#39;<br />&#160; });<br />&#160; // Search toolbar.<br />&#160; mygrid.jqGrid(&#39;filterToolbar&#39;, {stringResult: true, searchOnEnter: false, defaultSearch : &#34;bw&#34;});<br />&#160; <br />}); <br />&#60;/script&#62;<br />&#160;<br />&#60;/head&#62;<br />&#60;body&#62;</p>
<p>&#60;table id=&#34;list&#34;&#62;&#60;tr&#62;&#60;td/&#62;&#60;/tr&#62;&#60;/table&#62; <br />&#60;div id=&#34;pager&#34;&#62;&#60;/div&#62; </p>
<p>&#60;/body&#62;<br />&#60;/html&#62;</p>
</div>
<p><input type='button' class='sfcodeselect' name='sfselectit5820' value='Select Code' data-codeid='sfcode5820' /></p>
<div class='sfcode' id='sfcode5820'>
<p>&#160;example.php</p>
<p>&#60;?php <br />$page = 1; //$_GET[&#39;page&#39;]; <br />&#160;<br />// get how many rows we want to have into the grid - rowNum parameter in the grid <br />$limit = 9; //$_GET[&#39;rows&#39;]; <br />&#160;<br />// get index row - i.e. user click to sort. At first time sortname parameter -<br />// after that the index from colModel <br />$sidx = &#39;invid&#39;; //$_GET[&#39;sidx&#39;]; <br />&#160;<br />// sorting order - at first time sortorder <br />$sord = &#39;invid&#39; ;//$_GET[&#39;sord&#39;]; <br />&#160;<br />// if we not pass at first time index use the first column for the index or what you want<br />if(!$sidx) $sidx =1; </p>
<p>// connect to the MySQL database server <br />$db = mysql_connect(&#39;localhost&#39;, &#39;user&#39;, &#39;user123&#39;) or die(&#34;Connection Error: &#34; . mysql_error()); <br />$database = &#39;test&#39;;<br />// select the database <br />mysql_select_db($database) or die(&#34;Error connecting to db.&#34;); <br />&#160;<br />// calculate the number of rows for the query. We need this for paging the result <br />$result = mysql_query(&#34;SELECT COUNT(*) AS count FROM invheader&#34;); <br />$row = mysql_fetch_array($result,MYSQL_ASSOC); <br />$count = $row[&#39;count&#39;]; <br />&#160;<br />// calculate the total pages for the query <br />if( $count &#62; 0 &#38;&#38; $limit &#62; 0) { <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $total_pages = ceil($count/$limit); <br />} else { <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $total_pages = 0; <br />} <br />&#160;<br />// if for some reasons the requested page is greater than the total <br />// set the requested page to total page <br />if ($page &#62; $total_pages) $page=$total_pages;<br />&#160;<br />// calculate the starting position of the rows <br />$start = $limit*$page - $limit;<br />&#160;<br />// if for some reasons start position is negative set it to 0 <br />// typical case is that the user type 0 for the requested page <br />if($start &#60;0) $start = 0; <br />&#160;<br />// the actual query for the grid data <br />$SQL = &#34;SELECT invid, invdate, amount, tax, total, note FROM invheader ORDER BY $sidx , $sord LIMIT $start , $limit&#34;; <br />$result = mysql_query( $SQL ) or die(&#34;Couldn&#39;t execute query.&#34;.mysql_error()); <br />&#160;<br />// we should set the appropriate header information. Do not forget this.<br />header(&#34;Content-type: text/xml;charset=utf-8&#34;);<br />&#160;<br />$s&#160; = &#34;&#60;?xml version=&#39;1.0&#39; encoding=&#39;utf-8&#39;?&#62;&#34;;<br />$s .= &#34;&#60;rows&#62;&#34;;<br />$s .= &#34;&#60;page&#62;&#34;.$page.&#34;&#60;/page&#62;&#34;;<br />$s .= &#34;&#60;total&#62;&#34;.$total_pages.&#34;&#60;/total&#62;&#34;;<br />$s .= &#34;&#60;records&#62;&#34;.$count.&#34;&#60;/records&#62;&#34;;</p>
<p>// be sure to put text data in CDATA<br />while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {<br />&#160;&#160;&#160; $s .= &#34;&#60;row id=&#39;&#34;. $row[&#39;invid&#39;].&#34;&#39;&#62;&#34;;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;<br />&#160;&#160;&#160; $s .= &#34;&#60;cell&#62;&#34;. $row[&#39;invid&#39;].&#34;&#60;/cell&#62;&#34;;<br />&#160;&#160;&#160; $s .= &#34;&#60;cell&#62;&#34;. $row[&#39;invdate&#39;].&#34;&#60;/cell&#62;&#34;;<br />&#160;&#160;&#160; $s .= &#34;&#60;cell&#62;&#34;. $row[&#39;amount&#39;].&#34;&#60;/cell&#62;&#34;;<br />&#160;&#160;&#160; $s .= &#34;&#60;cell&#62;&#34;. $row[&#39;tax&#39;].&#34;&#60;/cell&#62;&#34;;<br />&#160;&#160;&#160; $s .= &#34;&#60;cell&#62;&#34;. $row[&#39;total&#39;].&#34;&#60;/cell&#62;&#34;;<br />&#160;&#160;&#160; $s .= &#34;&#60;cell&#62;&#60;![CDATA[&#34;. $row[&#39;note&#39;].&#34;]]&#62;&#60;/cell&#62;&#34;;<br />&#160;&#160;&#160; $s .= &#34;&#60;/row&#62;&#34;;<br />}<br />$s .= &#34;&#60;/rows&#62;&#34;; <br />&#160;<br />echo $s;</p>
<p>?&#62;</p>
</div>
<p>As you can see i have add in the third column (Amount) the abbility to be searched with e select menu.</p>
<p>The column amount has only this values (6.00 and 8.00). The problem is that i cannot make the select menu work.</p>
</p>
<p>I believe that xml file is responsible for this.</p>
</p>
<p>Does anyone know how can i make it work ?</p>
</p>
<p>Thanks in advance.</p></p>
]]></description>
        	        	<pubDate>Wed, 02 Nov 2011 21:23:06 +0200</pubDate>
        </item>
</channel>
</rss>