Setting up jqGrid is not terribly difficult, but customizing it can be somewhat more difficult. Take this paragraph from the wiki article on search:

There are four approaches:

* a toolbar searching
* a custom searching
* a single field searching
* a more complex approach involving many fields and conditions – advanced searching

These approaches use common options from jqGrid and so can be called only on an already-constructed grid. Every search method requires that some additional module should be included into the package. Also refer to Download or in every specific module on what should be included

But there are no links to article on the different search modules and the download page does not include any more details.

What to do? Here’s a working search function partially provided by Trirand support:

<script type="text/javascript">
	$.jgrid.no_legacy_api = true;
	$.jgrid.useJSON = true;
</script>

<script type="text/javascript">  
function searchContact(letter, field, oper)
{
	if(!oper) oper = 'bw';
	// build the filter
	var filter = {"groupOp":"OR","rules":[{"field":"FirstName","op":oper,"data":letter},{"field":"Lastname","op":oper,"data":letter},{"field":"Phone","op":oper,"data":letter}] };
	$("#Contactdatatable").jqGrid('setGridParam',{search:true, postData:{filters:filter} } );
	$("#Contactdatatable").trigger("reloadGrid");
	return false;
}

</script>

Here is what a modified version looks like in my Salesforce component:

        function search{!uid}(arg, field, oper)
        {
            if(!oper) oper = 'bw';
            if(field)   
                $enhanced{!uid}.jqGrid('setGridParam',{search:true, postData:{searchOper:oper,searchField:field, searchString:arg}});
            else {   
               
                var filter = {"groupOp":"OR","rules":{!colRulesJson} };            
                $enhanced{!uid}.jqGrid('setGridParam',{search:true, postData:{filters:filter} });
  
                }  
                
            $enhanced{!uid}.trigger("reloadGrid");
            return false;
        }

An editable, searchable implementation for Salesforce has just been finished as part of something I am working on for the Salesforce Foundation:

Soon to be generally available.

About these ads