views:

36

answers:

2

Would it at all be possible to show the current applied filter parameter as a descriptive string appended to the main title in the title bar

i.e.

"Customer - [ Field1 = 'ABC' and Field2 = 'CDE' ]"

Can't find an event that could be hooked onto once a filter is applied?

A: 

Try hooking into the afterShowSearch event, where you would update the grid header. From the docs:

This event fires (if defined) every time after the search dialog is shown

Justin Ethier
But does it fire when you use the toolbarSearch?
Jan de Jager
Ah.... no it does not. In that case have a look at `afterSearch`, from: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:toolbar_searching
Justin Ethier
A: 

I find that you not really need to have an event after the searching. At the every search request the data in the grid will be reloaded. So you can use events like beforeRequest, loadBeforeSend, serializeGridData, gridComplete or loadComplete.

From your title example I can suppose that you use "Advanced Searching". I want only demonstrate the main idea of the possible solution, so I choosed loadComplete to implement the capture change:

jQuery('#list').jqGrid({
    // ...
    loadComplete: function(data) {
        var postData = jQuery('#list').getGridParam("postData");
        var newCapture = "Title";
        if (postData._search === true && typeof postData.filters !== "undefined") {
            var filters = jQuery.parseJSON(postData.filters);
            newCapture = "Title: [";
            var rules = filters.rules;
            for (var i=0; i<rules.length; i++) {
                var rule = rules[i];
                var op = rule.op;  // the code name of the operation
                if (jQuery.fn.searchFilter && jQuery.fn.searchFilter.defaults &&
                    jQuery.fn.searchFilter.defaults.operators) {
                    // find op description 
                    var operators = jQuery.fn.searchFilter.defaults.operators;
                    for (var j=0; j<operators.length; j++) {
                        if (operators[j].op === rule.op) {
                            op = operators[j].text;
                            //op = $.jgrid.search.odata[j];
                            break;
                        }
                    }
                }
                newCapture += rule.field + " " + op + " '" + rule.data + "'";
                if (i+1 !== rules.length)
                    newCapture += ", ";
            }
            newCapture += "]";
        }
        jQuery('#list').setCaption(newCapture);
    }
});

If you don't use "Advanced Searching" you should searchField, searchOper and searchString instead of filters to build the grid title based on the search cafeteria.

Currently in the example I don't use localizes names for operation, but it's clear that one can do this.

Oleg