Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
Single Search Problem
29/05/2012
17:21
Avatar
nubieJoe
Canada
New Member
Members
Forum Posts: 1
Member Since:
29/05/2012
sp_UserOfflineSmall Offline

Hello everyone, 

I am very new to jqgrid, and have been trying for hours to get the single search working for my simple jqgrid. I researched online through Google/stackoverflow/search_adv demo code and still to no avail.

Here is my relavent javascript and PHP code. I think the main problem is that the _search is not passed so, my $where is always empty.

<script type="text/javascript">

$(function() {

//This function creates the table, search on jqGrid demo for simpler example to understand

$("#list").jqGrid({

url:'main-grid.php',

datatype: 'json',

mtype: 'POST',

colNames:['Items', 'Item Number'],

colModel :[

{name:'textbook', index:'textbook', width:100, searchoptions:{sopt:['eq']}},

{name:'poNum', index:'poNum', width:30, align:'center', searchoptions:{sopt:['eq','ne','lt','le','gt','ge']}}

],

pager: '#pager',

rowNum: 100,

sortname: 'bookID',

sortorder: 'desc',

viewrecords: false,

autowidth: true,

height: 600,

});

$("#list").jqGrid('navGrid','#pager',{edit:false,add:false,del:false,searchtext:"Search"});

});

</script>

/*PHP*/

//array to translate the search type

$ops = array(

'eq'=>'=', //equal

'ne'=>'<>',//not equal

'lt'=>'<', //less than

'le'=>'<=',//less than or equal

'gt'=>'>', //greater than

'ge'=>'>=',//greater than or equal

'bw'=>'LIKE', //begins with

'bn'=>'NOT LIKE', //doesn't begin with

'in'=>'LIKE', //is in

'ni'=>'NOT LIKE', //is not in

'ew'=>'LIKE', //ends with

'en'=>'NOT LIKE', //doesn't end with

'cn'=>'LIKE', // contains

'nc'=>'NOT LIKE' //doesn't contain

);

function getWhereClause($col, $oper, $val){

global $ops;

if($oper == 'bw' || $oper == 'bn') $val .= '%';

if($oper == 'ew' || $oper == 'en' ) $val = '%'.$val;

if($oper == 'cn' || $oper == 'nc' || $oper == 'in' || $oper == 'ni') $val = '%'.$val.'%';

return "AND $col {$ops[$oper]} '$val' ";

}

$where = ""; //if there is no search request sent by jqgrid, $where should be empty

if ($_REQUEST['_search'] == 'true') {

$where = getWhereClause($searchField,$searchOper,$searchString);

}

// Database Connection

$con = mysql_connect ( $db_server, $db_username, $db_password ) or die('Could not connect: '. mysql_error());;

$db_select = mysql_select_db ( $db_name ) or die('Failed to access the database: '. mysql_error());

$query = "SELECT po.poNum, book.id, book.textbook FROM $tb_po po, $tb_book book WHERE book.id=po.bookID ".$where. " ORDER BY $sidx $sord";

$result = mysql_query ( $query ) or die ( "Querying failed "" . $tb_book . "" and "" . $tb_po . "". " . mysql_error() );

$count = mysql_num_rows($result);

$responce = new stdClass;

//$responce->page = new stdClass;

$responce->page = 1;

//$responce->total = new stdClass;

$responce->total = 1;

//$responce->records = new stdClass;

$responce->records = $count;

$i = 0;

while( $row = mysql_fetch_array($result)){

//$responce->rows[$i]['id'] = new stdClass;

//$responce->rows[$i]['cell'] = new stdClass;

$responce->rows[$i]['id']= $row['id'];

$responce->rows[$i]['cell']=array($row['textbook'],$row['poNum']);

$i++;

}

echo json_encode($responce);

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
170 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information