Scott R. Keszler > Catalyst-TraitFor-Controller-jQuery-jqGrid-Search-0.02 > Catalyst::TraitFor::Controller::jQuery::jqGrid::Search



Annotate this POD

View/Report Bugs
Module Version: 0.02   Source  


Catalyst::TraitFor::Controller::jQuery::jqGrid::Search - Catalyst helper function for translating jqGrid search parameters


Version 0.02


Helper for translating search queries from the jQuery plugin jqGrid.

In your Catalyst Controller.

  package MyApp::Web::Controller::Root;

  use Moose;
  use namespace::autoclean;

  with 'Catalyst::TraitFor::Controller::jQuery::jqGrid::Search';

Then later on in your controllers you can do

  sub foo :Local {
    my ($self, $c) = @_;

    my $search_filter = $self->jqGrid_search($c->req->params);

    my $bar_rs = $c->model('DB::Baz')->search(


The Javascript library simplifies the writing of Javascript and does for Javascript what the MVC model does for Perl.

A very useful plugin to jQuery is a Grid control which can be used to page through data obtained from a back-end database. Ajax calls to the back-end retrieve JSON data. See

This module provides a helper function to translate the jqGrid simple and/or complex search query strings to the DBIx::Class / SQL::Abstract search/where constructs.



Simple Search (single field)

jqGrid submits the parameters searchField, searchOper, and searchString. For example, the query "cust_name = 'Bob'" would set:

  searchField  = 'cust_name'
  searchOper   = 'eq'
  searchString = 'Bob'

jqGrid_search translates that into:

  { 'cust_name' => { '=' => 'Bob' } }

Complex Search

jqGrid submits the parameter filters with JSON-encoded data. For example, the query: "( (name LIKE "%Bob%" AND tax >= 20) OR (note LIKE "no tax%" AND amount < 1000) )" would result in the following:

  filters = '{"groupOp":"OR","rules":[],"groups":[{"groupOp":"AND","rules":[{"field":"name","op":"cn","data":"Bob"},
             "data":"no tax"},{"field":"amount","op":"lt","data":"1000"}],"groups":[]}]}'

jqGrid_search translates that into:

    '-or' => [
        '-and' => [
          { 'name'   => { '-like' => '%Bob%' } },
          { 'tax'    => { '>=' => '20' } }
        '-and' => [
          { 'note'   => { '-like' => 'no tax%' } },
          { 'amount' => { '<' => '1000' } }

The jqGrid Search Operators are:

jqGrid Search Setup

In your jqGrid colModel options, be sure to set sensible search operators for each field in the sopt option within searchoptions. For example, the various like-like operators (bw, ew, etc.) probably don't make sense for a numeric field. Similarly, anything other than eq for a boolean field is unnecessary.


JSON - for parsing the jqGrid "complex search" parameter filters.


Scott R. Keszler, <keszler at>


Please report any bugs or feature requests to bug-catalyst-traitfor-controller-jquery-jqgrid-search at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

perldoc Catalyst::TraitFor::Controller::jQuery::jqGrid::Search

You can also look for information at:


Thanks to Ian Docherty <> for Catalyst::TraitFor::Controller::jQuery::jqGrid, which I used as a template for this code.


Copyright 2012 Scott R. Keszler.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.

syntax highlighting: