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
Toolbar Search and Multi Filter Search
13/01/2012
17:53
Avatar
nate215
Member
Members
Forum Posts: 5
Member Since:
14/12/2011
sp_UserOfflineSmall Offline

Hi 

I have set up JQgrid i have the regular single search working, but the advanced toolbar and and multisearch will not work. I am able to pull up the functions and see them but they filter no results. I have even seen in firebug when it searchs it is sending the right request but puls back all data. Im sure im missing something in my server code but struggled to see what it is. 

jQuery(document).ready(function(){

jQuery("#list").jqGrid({

url:'serverjson.php',

datatype: "json",

mtype: 'GET',

colNames:['id','Date', 'Name','Address 1','Address 2','City','Province','Postal','Gender','Phone','Value Card','Sharps','Fresh','Comments','Email','Manager','Domain'],

colModel:[

{name:'CUSTOMER_ID', index:'CUSTOMER_ID', width:55, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:false},

{name:'DATE_ENTERED', index:'DATE_ENTERED', width: 90, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:false},

{name:'NAME', index:'NAME', width: 250, align:'left',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'ADDRESS1', index:'ADDRESS1', width:150, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'ADDRESS2', index:'ADDRESS2', width:150, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'CITY', index:'CITY', width:150, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'PROVINCE', index:'PROVINCE', width:80, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'POSTAL', index:'POSTAL', width:120, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'GENDER', index:'GENDER', width:80, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'PHONE', index:'PHONE', width:80, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'CUSTOMER_NUMBER', index:'CUSTOMER_NUMBER', width:80, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'SHARPS', index:'SHARPS', width:80, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'FRESH', index:'FRESH', width:80, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'COMMENTS', index:'COMMENTS', width:80, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'EMAIL', index:'EMAIL', width:80, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'MANAGER', index:'MANAGER', width:80, align:'center',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

{name:'DOMAIN', index:'DOMAIN', width:150, align:'left',

searchoptions:{sopt:['eq','ne','lt','le','gt','ge','bw','ew','cn','nc']},

editable:true},

],

rowNum: 10,

rowList:[10,20,30],

loadonce: false,

gridview:true,

height: "100%",

pager: '#pager',

sortname: 'CUSTOMER_ID',

viewrecords: true,

sortorder: "asc",

caption:"- Customer Details",

editurl:"server3.php",

pagination: true,

shrinktofit:false,

width:"960",

});

jQuery("#list").jgrid = {

search : {

caption: "Search...",

Find: "Find",

Reset: "Reset",

odata : ['equal', 'not equal', 'less', 'less or equal','greater','greater or equal', 'begins with','does not begin with','is in','is not in','ends with','does not end with','contains','does not contain'],

groupOps: [ { op: "AND", text: "all" }, { op: "OR", text: "any" } ],

matchText: " match",

rulesText: " rules"

}},

jQuery("#list").jqGrid('navGrid','#pager',{ view: true, del: false, add: true, edit: true },

{}, // default settings for edit

{}, // default settings for add

{}, // delete

{closeOnEscape: true, multipleSearch: false ,

closeAfterSearch: true }, // search options

{}

);

//jQuery("#list").jqGrid('filterToolbar', {stringResult: true, searchOnEnter: false, defaultSearch:"eq"});

});

Server Code:

<?php

// database connection information is stored here

include("dbconfig.php");

// The first four variables retrieve parameters for

// table creation. (Some for searching also.)

$page = $_REQUEST['page']; // requested page

$limit = $_REQUEST['rows']; // rows per page

$sidx = $_REQUEST['sidx']; // index row

$sord = $_REQUEST['sord']; // sorting order

// if index isn't passed then use the first column

if(!$sidx) $sidx=1;

// these three variables are used to search for records

$where = $_REQUEST['searchField']; // field to be searched

$whereValue = $_REQUEST['searchString']; // value to be looked for

$whereOper = $_REQUEST['searchOper']; // operator used

// If $whereOper was passed then cofigure the SQL operator

// and what we are searching for. There are a couple of

// these remarked out because honestly I do not know the mySQL

// syntax and I really don't need it for this project.

if ($whereOper <> NULL) {

switch($whereOper){

case("eq"):

$sqlOperator = " = ";

$whereValue = "'".$whereValue."'";

break;

case("ne"):

$sqlOperator = " <> ";

$whereValue = "'".$whereValue."'";

break;

case("lt"):

$sqlOperator = " < ";

$whereValue = "'".$whereValue."'";

break;

case("le"):

$sqlOperator = " <= ";

$whereValue = "'".$whereValue."'";

break;

case("gt"):

$sqlOperator = " > ";

$whereValue = "'".$whereValue."'";

break;

case("ge"):

$sqlOperator = " >= ";

$whereValue = "'".$whereValue."'";

break;

case("bw"):

$sqlOperator = " REGEXP '^";

$whereValue = $whereValue."'" ;

break;

// case("bn"):

// $sqlOperator = "=";

// $whereValue = "'".$whereValue."'";

// break;

// case("in"):

// $sqlOperator = "=";

// $whereValue = "'".$whereValue."'";

// break;

// case("ni"):

// $sqlOperator = "=";

// $whereValue = $whereValue."'";

// break;

case("ew"):

$sqlOperator = " LIKE '%";

$whereValue = $whereValue."'";

break;

// case("en"):

// $sqlOperator = "=";

// $whereValue = "'".$whereValue."'";

// break;

case("cn"):

$sqlOperator = " LIKE '%";

$whereValue = $whereValue."%'";

break;

case("nc"):

$sqlOperator = " NOT LIKE '%";

$whereValue = $whereValue."%'";

break;

}

}

// Connect to the MySQL database server

$db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Connection Error: " . mysql_error());

// Select the database

mysql_select_db($database) or die("Error connecting to db.");

// if $where is not NULL then get the count on the search criteria,

// else get the count on everything.

if ($where <> NULL){

$result = mysql_query("SELECT COUNT(*) AS count FROM CUSTOMER WHERE ".$where.$sqlOperator.$whereValue);

} else {

$result = mysql_query("SELECT COUNT(*) AS count FROM CUSTOMER");

}

// Calculate the number of rows for the query.

// This is used for paging the result.

$row = mysql_fetch_array($result, MYSQL_ASSOC);

$count = $row['count'];

// calculate the total pages for the query

if($count > 0) {

$total_pages = ceil($count/$limit);

} else {

$total_pages = 0;

}

// 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;

// if where is not null then retrieve requested rows based on search

// else retrieve everything

if ($where <> NULL) {

$SQL = "SELECT CUSTOMER_ID, DATE_ENTERED, NAME, ADDRESS1, ADDRESS2, CITY, PROVINCE, POSTAL, GENDER, PHONE, CUSTOMER_NUMBER, SHARPS, FRESH, COMMENTS, EMAIL, MANAGER, DOMAIN FROM CUSTOMER WHERE ".$where.$sqlOperator.$whereValue." ORDER BY ".$sidx." ".$sord." LIMIT ".$start." , ".$limit;

$result = mysql_query($SQL) or die("Could not execute query ".$SQL." ".mysql_error());

} else {

$SQL = "SELECT CUSTOMER_ID, DATE_ENTERED, NAME, ADDRESS1, ADDRESS2, CITY, PROVINCE, POSTAL, GENDER, PHONE, CUSTOMER_NUMBER, SHARPS, FRESH, COMMENTS, EMAIL, MANAGER, DOMAIN FROM CUSTOMER ORDER BY ".$sidx." ".$sord." LIMIT ".$start." , ".$limit;

$result = mysql_query($SQL) or die("Could not execute query. ".mysql_error());

}

// echo $SQL . "<br />";

// response back to web page

$response->page = $page;

$response->total = $total_pages;

$response->records = $count;

$i=0;

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

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

$response->rows[$i]['cell']=array($row[CUSTOMER_ID], $row[DATE_ENTERED], $row[NAME], $row[ADDRESS1], $row[ADDRESS2],

$row[CITY], $row[PROVINCE], $row[POSTAL], $row[GENDER], $row[PHONE],$row[CUSTOMER_NUMBER],$row[SHARPS],$row[FRESH],$row[COMMENTS],$row[EMAIL],$row[MANAGER], $row[DOMAIN]);

$i++;

}

echo json_encode($response);

mysql_close($db);

?>

Thanks in advance

17/01/2012
21:15
Avatar
nate215
Member
Members
Forum Posts: 5
Member Since:
14/12/2011
sp_UserOfflineSmall Offline

Hi sorry to ask again but im really struggling with this i know it has something to do with the filters but just cant see where i am going wrong.

Thanks

17/01/2012
21:46
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello,

if you use multipleSearch:true option the information about the filters will be sent in another format (see the documentation). So you have to modify your server code so that you analyse the 'filters' parameter instead of 'searchField', 'searchString' and 'searchOper' which you do currently.

I don't use PHP myself so I can't give you more code recommendation.

Best regards
Oleg 

17/01/2012
23:13
Avatar
nate215
Member
Members
Forum Posts: 5
Member Since:
14/12/2011
sp_UserOfflineSmall Offline

Thanks for your response, I have been trying with the search_adv.php demo page but with no success. When i search it just reloads the whole grid.

17/01/2012
23:45
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

I could not help you with PHP code (search_adv.php for example) because I didn't use it myself. I just can see that the code which you posted is written definitively for the simple searching and can't work in your case.

Probably some PHP developer who read the forum can help you.

28/09/2013
06:50
Avatar
muni
New Member
Members
Forum Posts: 2
Member Since:
30/06/2013
sp_UserOfflineSmall Offline

I had implemented this searchhing functionality, it working fine for me.

check out here...

http://www.smarttutorials.net/.....-and-ajax/

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
33 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