1

I have a five column(2 integer,3 String column) grid with column filter. i want search operations for integer values(greater,less,equal) its working fine, i don't want search operations for string column.

I am using back end search.

What am expecting is attached the model image as below please find it

i want search but i don't want search operations for String having columns

How to remove search operations in selected column. please help me.

enter image description here

jQuery("#list451").jqGrid({
    url: 'localset.php',
    datatype: "json",
    height: 255,
    width: 600,
    colNames: ['Index', 'Name', 'Code', 'N Name', 'C Name'],
    colModel: [{
            name: 'item_id',
            index: 'item_id',
            width: 65,
            sorttype: 'integer',
            searchoptions: {
                sopt: ['eq', 'ne', 'le', 'lt', 'gt', 'ge']
            }
        }, {
            name: 'name',
            index: 'name',
            width: 150,
            sorttype: 'string',
            searchoptions: {
                sopt: []
            }
        }, {
            name: 'code',
            index: 'code',
            width: 150,
            sorttype: 'string',
            searchoptions: {
                sopt: ['eq', 'bw', 'bn', 'cn', 'nc', 'ew', 'en']
            }
        }, {
            name: 'n_name',
            index: 'n_name',
            width: 150,
            sorttype: 'string',
            searchoptions: {
                sopt: []
            }
        }, {
            name: 'c_name',
            index: 'c_name',
            width: 150,
            sorttype: 'string',
            searchoptions: {
                sopt: []
            }
        },
        rowNum: 50,
        rowTotal: 200,
        rowList: [20, 30, 50],
        loadonce: true,
        mtype: "GET",
        rownumbers: true,
        rownumWidth: 40,
        gridview: true,
        pager: '#pager451',
        sortname: 'item_id',
        viewrecords: true,
        sortorder: "asc",
        caption: "Loading data from server at once"
    }); jQuery("#list451").jqGrid('filterToolbar', {
    searchOperators: true
});
xxbinxx
  • 1,527
  • 11
  • 18

3 Answers3

2

Use search:false in your colModel for columns you dont need searching.

UPDATE
You can customize the search option in your Grid by replacing searchoptions: with searchrules

searchrules:{custom:true, custom_func: fnc_myStringCheck }, search:true }   

Make sure the stype is text (though it is by default) and fnc_myStringCheck for your custom method. Hope this helps.

Wahab
  • 520
  • 5
  • 24
  • i want search but i don't want search operations – Krishnakumar Subbaiyan Aug 26 '14 at 08:51
  • Can you explain why you need a filter column without any search option. – Wahab Aug 26 '14 at 08:58
  • integer columns i want search operations. String column i will implement customized search like (Lor* /man). so i want search without search operations. – Krishnakumar Subbaiyan Aug 26 '14 at 09:05
  • Wahab Thanks for spend time for me. .i don't want put every column search rules.please help me for remove search operations for string columns. – Krishnakumar Subbaiyan Aug 26 '14 at 09:47
  • I am sorry, i couldn't understand ur requirement. "i don't want put every column search rules" then use a generalized search like this **grid.jqGrid('filterToolbar', {autosearch : true, searchOnEnter:false, defaultSearch : "cn",});** but if you want to have customized search for column u hav to implement individually in colModel – Wahab Aug 26 '14 at 09:58
  • Hi Wahab, i will implement many different type of customize search for every column. so it will implement back end side. i want remove search operations only,Please you don't worry about my requirement. – Krishnakumar Subbaiyan Aug 26 '14 at 10:13
1

I find your question very interesting and so I prepared the demo which shows how the problem can be solved. The results looks like on the picture below:

enter image description here

The current version of jqGrid support clearSearch which can be defined for every specific column, but it didn't support column specific searchOperators option. There are only searchOperators option of filterToolbar applied to all columns.

The demo calls normalizeFilterToolbar function which hide the part of searching input with the searing operation for all columns where either new searchOperators: false option are used in the column definition or where only one operation are specified (for example is no sopt are defined in searchoptions or if no searchoptions at all are defined). The corresponding code looks

var $grid = $("#list"), // the grid
    normalizeFilterToolbar = function () {
        var $self = this,
            colModel = $self.jqGrid("getGridParam", "colModel"),
            $searchToolbarColumns = $self.closest(".ui-jqgrid-view")
                .find(">.ui-jqgrid-hdiv .ui-jqgrid-htable .ui-search-toolbar>.ui-th-column"),
            cCol = colModel.length,
            iCol,
            cm;

        for (iCol = 0; iCol < cCol; iCol++) {
            cm = colModel[iCol];
            if (cm.searchoptions == null ||
                    ((cm.searchoptions.sopt == null || cm.searchoptions.sopt.length === 1) && cm.searchoptions.searchOperators !== true) ||
                    (cm.searchoptions.searchOperators === false)) {
                // hide the searching operation for the column
                $($searchToolbarColumns[iCol]).find(">div>.ui-search-table .ui-search-oper").hide();
            }
        }
    };

// create the grid
$grid.jqGrid({
    // ... the options
});

$grid.jqGrid("filterToolbar", {searchOperators: true, defaultSearch: "cn"});
normalizeFilterToolbar.call($grid);
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks a lot Oleg. Oleg its working very fine.Very Nice Example. – Krishnakumar Subbaiyan Aug 29 '14 at 09:34
  • How to add Reset search value x button in number format text box. Oleg Please add the code . – Krishnakumar Subbaiyan Aug 29 '14 at 09:55
  • @KrishnakumarSubbaiyan: One can define `clearSearch: false` or `clearSearch: true` (default is true) in every column. I used `clearSearch: false` in `numberTemplate` in my demo. Just remove `clearSearch: false` if you need to see "x" button in numeric searching fields. – Oleg Aug 29 '14 at 09:59
0

static way:

colModel : [ 
                    {
                        name : 'sequenceId',
                        index : ' ',
                        search: false,
                        sortable : true,
                        classes: 'wrap'
                    }

dynamic way:

colModel : [ 
                    {
                        name : 'sequenceId',
                        index : ' ',
                        sortable : true,
                        classes: 'wrap',
                        formatter: disableSearch
                    }
function disableSearch(cellvalue, options, rowObject) {
    options.colModel.search = false;
    return cellvalue;
}