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_TopicIcon
Toolbar Search or Filter
15/10/2010
06:15
Avatar
nickelj
Member
Members
Forum Posts: 28
Member Since:
15/10/2010
sp_UserOfflineSmall Offline

Hey...thanks for making jqgrid - looks great!

I am just getting started and I have a couple things.

In the examples (/blog/jqgrid/jqgrid.html), under New in version 3.7 is Toolbar Search.

It is spelt "Tooolbar search" - small thing I know.

More importantly, the PHP code shows a reference to a "$where" variable, but this variable is never declared or calculated. How do you get the filter information into the "$where" variable?

The code for the Virtual scrolling looks exactly the same...it doesn't explain the "$where" variable either.

I don't suppose there is anywhere to download examples from to run on my own server? It would sure help to have a few working examples (I am using PHP and MySQL).

Jim

16/10/2010
04:58
Avatar
nickelj
Member
Members
Forum Posts: 28
Member Since:
15/10/2010
sp_UserOfflineSmall Offline

Took me a while, but I tracked down some code that seems to work.

Just thought I would share with the group:

<CODE>

$where = "";
$searchOn = $_REQUEST['_search'];
if($searchOn=='true') {
        $searchstr = $_REQUEST['filters'];
        $where = constructWhere($searchstr);
}
function constructWhere($s){
    $qwery = "";
        //['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc']
    $qopers = array(
                  'eq'=>" = ",
                  'ne'=>" <> ",
                  'lt'=>" < ",
                  'le'=>" <= ",
                  'gt'=>" > ",
                  'ge'=>" >= ",
                  'bw'=>" LIKE ",
                  'bn'=>" NOT LIKE ",
                  'in'=>" IN ",
                  'ni'=>" NOT IN ",
                  'ew'=>" LIKE ",
                  'en'=>" NOT LIKE ",
                  'cn'=>" LIKE " ,
                  'nc'=>" NOT LIKE " );
    if ($s) {
        $jsona = json_decode($s,true);
        if(is_array($jsona)){
                $gopr = $jsona['groupOp'];
                $rules = $jsona['rules'];
            $i =0;
            foreach($rules as $key=>$val) {
                $field = $val['field'];
                $op = $val['op'];
                $v = $val['data'];
                if($v && $op) {
                  $i++;
                  // ToSql in this case is absolutley needed
                  $v = ToSql($field,$op,$v);
                  if ($i == 1) {
                     $qwery = "WHERE ";
                  } else {
                     $qwery .= " " .$gopr." ";
                  }
                                        switch ($op) {
                                                // in need other thing
                                            case 'in' :
                                            case 'ni' :
                                                $qwery .= $field.$qopers[$op]." (".$v.")";
                                                break;

                                            default:
                                                $qwery .= $field.$qopers[$op].$v;
                                        }
                                }
            }
        }
    }
    return $qwery;
}
function ToSql ($field, $oper, $val) {
        // we need here more advanced checking using the type of the field - i.e. integer, string, float
        switch ($field) {
                case 'id':
                        return intval($val);
                        break;
                case 'amount':
                case 'tax':
                case 'total':
                        return floatval($val);
                        break;
                default :
                        //mysql_real_escape_string is better
                        if($oper=='bw' || $oper=='bn') return "'" . addslashes($val) . "%'";
                        else if ($oper=='ew' || $oper=='en') return "'%" . addcslashes($val) . "'";
                        else if ($oper=='cn' || $oper=='nc') return "'%" . addslashes($val) . "%'";
                        else return "'" . addslashes($val) . "'";
        }
}

24/07/2011
08:30
Avatar
GeorgeIoak
Member
Members
Forum Posts: 4
Member Since:
23/07/2011
sp_UserOfflineSmall Offline

I found your code and was trying to use it but have run into some problems. I added some debug code to check the SQL statement and I found that the WHERE clause was not being created.

searchstr variable is set to: 

{"groupOp":"AND","rules":[{"field":"lname","op":"bw","data":"s"

}]}

but json_decode returns empty.

When I use FireBug to look at the parameters I see that filters is set to:

{"groupOp":"AND","rules":[{"field":"lname","op":"bw","data":"s"}]}

Are the "" the problem why json_decode is not working and if so where did they come from??
24/07/2011
08:57
Avatar
GeorgeIoak
Member
Members
Forum Posts: 4
Member Since:
23/07/2011
sp_UserOfflineSmall Offline

Found it!

Change

$searchstr = $_REQUEST['filters'];

to:

$searchstr = stripslashes($_REQUEST['filters']);

ans this works for me at least with the initial testing in FF

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

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