Hello
I've downloaded and installed jqgrid 3.6.1 and succeded in display datas form mysql database. I'm able to sort datas by clicking columns, show 10 20 or 30 records in grid, go to the next records… and open search box. Problem is when I'm click searching datas are not filtered.
Thank you for your help
html page
|
1 |
<span class="doctype"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"></span><br /><<span class="start-tag">html</span><span class="attribute-name"> xmlns</span>=<span class="attribute-value">"http://www.w3.org/1999/xhtml" </span><span class="attribute-name">xml:lang</span>=<span class="attribute-value">"en" </span><span class="attribute-name">lang</span>=<span class="attribute-value">"en"</span>><br /><<span class="start-tag">head</span>><br /><<span class="start-tag">meta</span><span class="attribute-name"> http-equiv</span>=<span class="attribute-value">"Content-Type" </span><span class="attribute-name">content</span>=<span class="attribute-value">"text/html; charset=utf-8"</span>><br /><<span class="start-tag">title</span>>My First Grid</<span class="end-tag">title</span>><br /> <br /><<span class="start-tag">link</span><span class="attribute-name"> rel</span>=<span class="attribute-value">"stylesheet" </span><span class="attribute-name">type</span>=<span class="attribute-value">"text/css" </span><span class="attribute-name">media</span>=<span class="attribute-value">"screen" </span><span class="attribute-name">href</span>=<span class="attribute-value">"css/ui-lightness/jquery-ui-1.7.2.custom.css"</span>><br /><<span class="start-tag">link</span><span class="attribute-name"> rel</span>=<span class="attribute-value">"stylesheet" </span><span class="attribute-name">type</span>=<span class="attribute-value">"text/css" </span><span class="attribute-name">media</span>=<span class="attribute-value">"screen" </span><span class="attribute-name">href</span>=<span class="attribute-value">"css/ui.jqgrid.css"</span>><br /><<span class="start-tag">link</span><span class="attribute-name"> rel</span>=<span class="attribute-value">"stylesheet" </span><span class="attribute-name">type</span>=<span class="attribute-value">"text/css" </span><span class="attribute-name">media</span>=<span class="attribute-value">"screen" </span><span class="attribute-name">href</span>=<span class="attribute-value">"css/jquery.searchFilter.css"</span>><br /> <br /><<span class="start-tag">style</span>><br />html, body {<br /> margin: 0;<br /> padding: 0;<br /> font-size: 75%;<br />}<br /></<span class="end-tag">style</span>><br /><<span class="start-tag">script</span><span class="attribute-name"> src</span>=<span class="attribute-value">"js/jquery-1.3.2.min.js" </span><span class="attribute-name">type</span>=<span class="attribute-value">"text/javascript"</span>></<span class="end-tag">script</span>><br /><<span class="start-tag">script</span><span class="attribute-name"> src</span>=<span class="attribute-value">"js/i18n/grid.locale-fr.js" </span><span class="attribute-name">type</span>=<span class="attribute-value">"text/javascript"</span>></<span class="end-tag">script</span>><br /> |
|
1 |
<<span class="start-tag">script</span><span class="attribute-name"> type</span>=<span class="attribute-value">"text/javascript"</span>><br /> jQuery.jgrid.useJSON = true;<br /></<span class="end-tag">script</span>><br /><<span class="start-tag">script</span><span class="attribute-name"> src</span>=<span class="attribute-value">"js/jquery.jqGrid.min.js" </span><span class="attribute-name">type</span>=<span class="attribute-value">"text/javascript"</span>></<span class="end-tag">script</span>><br /><<span class="start-tag">script</span><span class="attribute-name"> type</span>=<span class="attribute-value">"text/javascript"</span>><br /> jQuery.extend(jQuery.jgrid,{<br /> parse:function(jsstring) {<br /> return JSON.parse(jsstring);<br /> }<br /> });<br /></<span class="end-tag">script</span>><br /><br /><br /><br /><br /><<span class="start-tag">script</span><span class="attribute-name"> type</span>=<span class="attribute-value">"text/javascript"</span>><br />jQuery().ready(function (){ <br /> jQuery("#list").jqGrid({<br /> url:'grid.php?q=1',<br /> datatype: 'xml',<br /> colNames:['numero','organisme', 'maj'],<br /> colModel :[ <br /> {name:'NUM', index:'numero', width:55}, <br /> {name:'ORG', index:'organisme', width:90}, <br /> {name:'MAJ', index:'maj', width:80, align:'right'}<br /> ],<br /> pager: '#pager',<br /> rowNum:10,<br /> rowList:[10,20,30],<br /> sortname: 'numero',<br /> sortorder: 'desc',<br /> viewrecords: true,<br /> caption: 'My first grid',<br /> sortname: 'numero', <br /> width:800,<br /> height:400,<br /><br /> }); jQuery("#list").jqGrid('navGrid','#pager',{edit:true,add:false,del:false});<br /><br />jQuery("#s2").click( function() { jQuery("#list").jqGrid('setGridParam',{sortname:"numero",sortorder:"asc"}).trigger("reloadGrid");<br /> }); <br />jQuery("#s1").click (function() { jQuery("#list").searchGrid( {sopt:['cn','bw','eq','ne','lt','gt','ew']} ); <br /> }); <br /> }); <br /></<span class="end-tag">script</span>><br /> <br /></<span class="end-tag">head</span>><br /><<span class="start-tag">body</span>><br /><<span class="start-tag">table</span><span class="attribute-name"> id</span>=<span class="attribute-value">"list"</span>></<span class="end-tag">table</span>> <br /><<span class="start-tag">div</span><span class="attribute-name"> id</span>=<span class="attribute-value">"pager"</span>></<span class="end-tag">div</span>> <br /> |
|
1 |
<<span class="start-tag">a</span><span class="attribute-name"> href</span>=<span class="attribute-value">"javascript:void(0)" </span><span class="attribute-name">id</span>=<span class="attribute-value">"s2"</span>>Set Sort to amount column</<span class="end-tag">a</span>><<span class="start-tag">a</span><span class="attribute-name"> href</span>=<span class="attribute-value">"javascript:void(0)" </span><span class="attribute-name">id</span>=<span class="attribute-value">"s1"</span>>Seaerch</<span class="end-tag">a</span>><br /></<span class="end-tag">body</span>><br /></<span class="end-tag">html</span>> |
|
1 |
<br />php file<br /><br /> |
$limit = $_GET['rows'];
// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel
$sidx = $_GET['sidx'];
// sorting order - at first time sortorder
$sord = $_GET['sord'];
// if we not pass at first time index use the first column for the index or what you want
if(!$sidx) $sidx =1;
mysql_connect("localhost", "xxxxxx", "xxxxxx") or die("Connection Error: " . mysql_error());
mysql_select_db("BDDRIPEINTRANET") or die("Connection Error: " . mysql_error());
// calculate the number of rows for the query. We need this for paging the result
$result = mysql_query("SELECT COUNT(*) AS count FROM organismes");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
// calculate the total pages for the query
if( $count > 0 && $limit > 0) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
// if for some reasons the requested page is greater than the total
// set the requested page to total page
if ($page > $total_pages) $page=$total_pages;
// calculate the starting position of the rows
$start = $limit*$page - $limit;
// if for some reasons start position is negative set it to 0
// typical case is that the user type 0 for the requested page
if($start <0) $start = 0;
// the actual query for the grid data
$SQL = "SELECT numero, organisme, maj FROM organismes ORDER BY $sidx $sord LIMIT $start , $limit";
$result = mysql_query( $SQL ) or die("Couldn't execute A.".mysql_error());
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
header("Content-type: application/xhtml+xml;charset=utf-8"); } else {
header("Content-type: text/xml;charset=utf-8");
} $et = ">";
echo "";
$s .= "
$s .= "
$s .= "
// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$s .= "
$s .= "
$s .= "
$s .= "
$s .= "
$s .= "
$s .= "
}
$s .= "";
echo $s;
?>
|
1 |
<br /> |
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top