Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7507555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:30:39+00:00 2026-05-29T22:30:39+00:00

I have a jqgrid containing some data to filter. I’d like to define a

  • 0

I have a jqgrid containing some data to filter. I’d like to define a combo box with some pre-defined filter sets / templates.
If a user selects an item of the combobox, the grid should automatically apply combined filters. Preferably, the combo box should be integrated into a toolbar or jqGrid’s pager, but also in the html page would be fine.

For example:

         COMBO BOX
       Item templates       filter parameters
        ___________
       |Expired    |        << Timeout = true
       |Last Week  |        << OpenDate between 02/13/2012 and 02/16/2012
       |Last Month |        << OpenDate between 01/01/2012 and 02/16/2012
       |.........  |        ......

Thanks in advance for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:30:39+00:00Added an answer on May 29, 2026 at 10:30 pm

    jqGrid supports Searching Templates in the Advance Searching (see “Searching”/ “Search Templates” in the official jqGrid demo), but there are currently no searching templates support in the Toolbar Filtering.

    I find your question very interesting. In the old question I described how one can use generic external filters to send additional information to the server. The way can be good in case of remote data, but it can’t be used directly in the local grid or in the grid with the loadonce: true option.

    So I created the demo which shows how the filter templates can be implemented in Toolbar Filtering and how to integrated the template in the jqGrid. I used toolbar: [true, “top”] to have additional empty toolbar above the column headers:

    enter image description here

    In the implementation I used the refreshSerchingToolbar function which I suggested originally here. It’s important to understand, that the refreshSerchingToolbar function fill in the filter toolbar only the information which can be exactly represented by the filter. For example the filter for “Closed” rows can be represented in the filter toolbar (see the picture above), but the interval of dates “Last Week” and “Last Month” con’t. In the cases the data in the grid will be filtered, but the corresponding fields of the filter toolbar stay empty.

    The most important part of the code of the demo you can find below

    var $grid = $("#list"),
        initDate = function (elem) {
            $(elem).datepicker({
                dateFormat: 'dd-M-yy',
                autoSize: true,
                changeYear: true,
                changeMonth: true,
                showButtonPanel: true,
                showWeek: true
            });
        },
        numberTemplate = {formatter: 'number', align: 'right', sorttype: 'number', editable: true/*,
            searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn', 'in', 'ni'] }*/},
        dateTemplate = {width: 80, align: 'center', sorttype: 'date',
                formatter: 'date', formatoptions: { newformat: 'd-M-Y' }, editable: true, datefmt: 'd-M-Y',
                editoptions: { dataInit: initDate },
                searchoptions: { sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'], dataInit: initDate }},
        yesNoTemplate = {align: 'center', editable: true, formatter: 'checkbox',
                edittype: 'checkbox', editoptions: {value: 'Yes:No', defaultValue: 'No'},
                stype: 'select', searchoptions: { sopt: ['eq', 'ne'], value: ':Any;true:Yes;false:No' }},
        myDefaultSearch = 'cn',
        getColumnIndex = function (columnIndex) {
            var cm = this.jqGrid('getGridParam', 'colModel'), i, l = cm.length;
            for (i = 0; i < l; i++) {
                if ((cm[i].index || cm[i].name) === columnIndex) {
                    return i; // return the colModel index
                }
            }
            return -1;
        },
        refreshSerchingToolbar = function (myDefaultSearch) {
            var filters, i, l, rules, rule, iCol, cmi, control, tagName,
                $this = $(this),
                postData = $this.jqGrid('getGridParam', 'postData'),
                cm = $this.jqGrid('getGridParam', 'colModel');
    
            for (i = 0, l = cm.length; i < l; i++) {
                control = $("#gs_" + $.jgrid.jqID(cm[i].name));
                if (control.length > 0) {
                    tagName = control[0].tagName.toUpperCase();
                    if (tagName === "SELECT") { // && cmi.stype === "select"
                        control.find("option[value='']")
                            .attr('selected', 'selected');
                    } else if (tagName === "INPUT") {
                        control.val('');
                    }
                }
            }
    
            if (typeof (postData.filters) === "string" &&
                    typeof (this.ftoolbar) === "boolean" && this.ftoolbar) {
    
                filters = $.parseJSON(postData.filters);
                if (filters && filters.groupOp === "AND" && typeof (filters.groups) === "undefined") {
                    // only in case of advance searching without grouping we import filters in the
                    // searching toolbar
                    rules = filters.rules;
                    for (i = 0, l = rules.length; i < l; i++) {
                        rule = rules[i];
                        iCol = getColumnIndex.call($this, rule.field);
                        if (iCol >= 0) {
                            cmi = cm[iCol];
                            control = $("#gs_" + $.jgrid.jqID(cmi.name));
                            if (control.length > 0 &&
                                    (((typeof (cmi.searchoptions) === "undefined" ||
                                    typeof (cmi.searchoptions.sopt) === "undefined")
                                    && rule.op === myDefaultSearch) ||
                                      (typeof (cmi.searchoptions) === "object" &&
                                          $.isArray(cmi.searchoptions.sopt) &&
                                          cmi.searchoptions.sopt.length > 0 &&
                                          cmi.searchoptions.sopt[0] === rule.op))) {
                                tagName = control[0].tagName.toUpperCase();
                                if (tagName === "SELECT") { // && cmi.stype === "select"
                                    control.find("option[value='" + $.jgrid.jqID(rule.data) + "']")
                                        .attr('selected', 'selected');
                                } else if (tagName === "INPUT") {
                                    control.val(rule.data);
                                }
                            }
                        }
                    }
                }
            }
        },
        templateClosed = {
            groupOp: "AND",
            rules: [
                { field: "closed", op: "eq", data: "true" }
            ]
        },
        templateLastWeek = {
            groupOp: "AND",
            rules: [
                { field: "invdate", op: "ge", "data": "13-Feb-2012" },
                { field: "invdate", op: "le", "data": "16-Feb-2012"}
            ]
        },
        templateLastMonth = {
            groupOp: "AND",
            rules: [
                { field: "invdate", op: "ge", "data": "16-Jan-2012" },
                { field: "invdate", op: "le", "data": "16-Feb-2012"}
            ]
        },
        myFilterTemplateLabel = 'Filter by Template:&nbsp;',
        myFilterTemplateNames = ['Closed', 'Last Week', 'Last Month'],
        myFilterTemplates = [templateClosed, templateLastWeek, templateLastMonth],
        iTemplate,
        cTemplates = myFilterTemplateNames.length,
        templateOptions = '',
        reloadWithNewFilterTemplate = function () {
            var iTemplate = parseInt($('#filterTemplates').val(), 10),
                postData = $grid.jqGrid('getGridParam', 'postData');
            if (isNaN(iTemplate)) {
                $grid.jqGrid('setGridParam', {search: false});
            } else if (iTemplate >= 0) {
                $.extend(postData, {
                    filters: JSON.stringify(myFilterTemplates[iTemplate])
                });
                $grid.jqGrid('setGridParam', {search: true});
            }
            $grid.trigger('reloadGrid', [{current: true, page: 1}]);
        };
    
    $grid.jqGrid({
        ...
        toolbar: [true, "top"],
        loadComplete: function () {
            var $this = $(this);
    
            if (typeof (this.ftoolbar) !== "boolean") {
                // create toolbar if needed
                $this.jqGrid('filterToolbar',
                    {stringResult: true, searchOnEnter: true, defaultSearch: myDefaultSearch});
            }
            refreshSerchingToolbar.call(this, myDefaultSearch);
        }
    });
    $.extend($.jgrid.search, {
        multipleSearch: true,
        multipleGroup: true,
        recreateFilter: true,
        closeOnEscape: true,
        closeAfterSearch: true,
        overlay: 0,
        tmplLabel: myFilterTemplateLabel,
        tmplNames: myFilterTemplateNames,
        tmplFilters: myFilterTemplates
    });
    $grid.jqGrid('navGrid', '#pager', {edit: false, add: false, del: false});
    for (iTemplate = 0; iTemplate < cTemplates; iTemplate++) {
        templateOptions += '<option value="' + iTemplate + '">' +
            myFilterTemplateNames[iTemplate] + '</option>';
    }
    $('#t_' + $.jgrid.jqID($grid[0].id)).append('<label for="filterTemplates">'+
        myFilterTemplateLabel + '</label>' +
        '<select id="filterTemplates"><option value="">Not filtered</option>' +
        templateOptions + '</select>');
    $('#filterTemplates').change(reloadWithNewFilterTemplate).keyup(function (e) {
        // some web browsers like Google Chrome don't fire "change" event
        // if the select will be "scrolled" by keybord. Moreover some browsers
        // like Internet Explorer don't change the select option on pressing
        // of LEFT or RIGHT key. Another web browsers like Google Chrome do this.
        // We make refrech of the grid in any from the cases. If needed one
        // could modify the code to reduce unnneded reloading of the grid,
        // but for the demo with a few local rows it's such optimization
        // isn't really needed
        var keyCode = e.keyCode || e.which;
    
        if (keyCode === $.ui.keyCode.PAGE_UP || keyCode === $.ui.keyCode.PAGE_DOWN ||
                keyCode === $.ui.keyCode.END || keyCode === $.ui.keyCode.HOME ||
                keyCode === $.ui.keyCode.UP || keyCode === $.ui.keyCode.DOWN ||
                keyCode === $.ui.keyCode.LEFT || keyCode === $.ui.keyCode.RIGHT) {
    
            reloadWithNewFilterTemplate();
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jqgrid in a modal popup that has data dependent on some
I have a jqGrid on a web page, with large data sets. Up to
I have a jqGrid with multiselect. I would like to be able to pre-check
I have jqGrid 3.5 (full) mostly working. I have it retrieving data with the
I have a case where I need to update a jqgrid based on some
I have a jqgrid with data loading from an xml stream (handled by django
I have a jqGrid in an ASP.Net MVC. The grid is defined as: $(#list).jqGrid({
I have an HTML form containing some textboxes and two jqGrids. The user selects
I have a JQGrid populated with data working correctly. The default sorting functionality is
Experts, I have JQGrid with custom template column like Edit. the following screen display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.