php - Problem using jqGrid Search Function -
i new jqgrid, want grips it. having hard time getting search function work. here xml working with:
<?xml version='1.0' encoding='utf-8'?> <rows> <page>1</page> <total>1</total> <records>3</records> <row id='1'> <cell>1</cell> <cell>5 little roodee</cell> <cell>hawarden</cell><cell>ch5 3pu</cell> <cell>895.00</cell> <cell>1</cell> </row> <row id='2'> <cell>2</cell> <cell>28 pant-y-fawnog</cell> <cell>buckley</cell> <cell>ch7 2pd</cell> <cell>610.00</cell> <cell>0</cell> </row> <row id='3'> <cell>3</cell> <cell>60 langford crescent</cell> <cell>buckley</cell> <cell>ch7 2pr</cell> <cell>625.00</cell> <cell>1</cell> </row> </rows>
as can see simple. here jqgrid declaration using:
$(function(){ $("#list").jqgrid({ url:'xml_properties_jq.php', datatype: 'xml', mtype: 'get', colnames:['id','address', 'town','postcode','rent. val','active'], colmodel :[ {name:'property_id', index:'property_id', width:40}, {name:'property_add_1', index:'property_add_1', width:150}, {name:'property_add_town', index:'property_add_town', width:80, align:'right', searchoptions: { sopt: ['eq', 'ne']}}, {name:'property_add_postcode', index:'property_add_postcode', width:80, align:'right'}, {name:'property_rentable_value', index:'property_rentable_value', width:80, align:'right'}, {name:'property_active', index:'property_active', width:60} ], pager: '#pager', rownum:10, rowlist:[10,20,30], sortname: 'property_id', sortorder: 'desc', viewrecords: true, caption: 'properties' }) //jquery("#list").jqgrid('navgrid','#pager',{edit:false,add:false,del:false}); .navgrid('#pager',{view:true, del:false}, {}, // use default settings edit {}, // use default settings add {}, // delete instead del:false need {multiplesearch : false}, // enable advanced searching {closeonescape:true} /* allow view dialog closed when user press esc key*/ ); });
finally here php constructs xml:
<?php //include information needed connection mysql data base server. // store here username, database , password include("connections/db.php"); // url parameter added 4 parameters described in colmodel // should these parameters construct needed query // since specify in options of grid use method // should use appropriate command obtain parameters. // in our case $_get. if specify want use post // should use $_post. maybe better way use $_request, // contain both , post variables. more information refer php documentation. // requested page. default grid sets 1. $page = $_get['page']; // how many rows want have grid - rownum parameter in grid $limit = $_get['rows']; // index row - i.e. user click sort. @ first time sortname parameter - // after index colmodel $sidx = $_get['sidx']; // sorting order - @ first time sortorder $sord = $_get['sord']; // if not pass @ first time index use first column index or want if(!$sidx) $sidx =1; // connect mysql database server //$db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("connection error: " . mysql_error()); // select database //mysql_select_db($db) or die("error connecting db."); mysql_select_db($database_eazylet, $eazylet); // calculate number of rows query. need paging result $result = mysql_query("select count(*) count p_properties", $eazylet); //$row = mysql_fetch_array($result,mysql_assoc); $row = mysql_fetch_assoc($result); $count = $row['count']; // calculate total pages query if( $count > 0 && $limit > 0) { $total_pages = ceil($count/$limit); } else { $total_pages = 0; } // if reasons requested page greater total // set requested page total page if ($page > $total_pages) $page=$total_pages; // calculate starting position of rows $start = $limit*$page - $limit; // if reasons start position negative set 0 // typical case user type 0 requested page if($start <0) $start = 0; // actual query grid data $sql = "select * p_properties order $sidx $sord limit $start , $limit"; $result = mysql_query($sql, $eazylet) or die("couldn't execute query.".mysql_error()); // should set appropriate header information. not forget this. header("content-type: text/xml;charset=utf-8"); $s = "<?xml version='1.0' encoding='utf-8'?>"; $s .= "<rows>"; $s .= "<page>".$page."</page>"; $s .= "<total>".$total_pages."</total>"; $s .= "<records>".$count."</records>"; // sure put text data in cdata while($row = mysql_fetch_array($result,mysql_assoc)) { //while($row = mysql_fetch_assoc($result)) { $s .= "<row id='". $row['property_id']."'>"; $s .= "<cell>". $row['property_id']."</cell>"; $s .= "<cell>". $row['property_add_1']."</cell>"; $s .= "<cell>". $row['property_add_town']."</cell>"; $s .= "<cell>". $row['property_add_postcode']."</cell>"; $s .= "<cell>". $row['property_rentable_value']."</cell>"; $s .= "<cell>". $row['property_active']."</cell>"; $s .= "</row>"; } $s .= "</rows>"; echo $s; ?>
all sorting works fine in grid assume data ok.
my problem when hit search button, enter valid criteria (i.e. id = 1) , click find, nothing happens. search box remains , list has not been filtered.
i have been working on day without success gratefully received!!
i using jquery v1.4.4 , jqgrid v3.8.2
many all
si
depend on kind of searching use server receive different additional parameters.
in case of single field searching searchfield
, searchstring
, searchoper
parameter. in case of advance searching 1 has 1 parameter filters
has in the json encoded form information parameters of search request. in case of toolbar searching , additional parameter stringresult:true
format of parameters same in case of advance searching.
so should append code analyse of parameters of searching request. can download the demo files the jqgrid download page , examine code of search_adv.php file example.
Comments
Post a Comment