4

I'm using jqGrid Filter Toolbar. I'm testing it with 2 columns, one numeric and the other alphanumeric.

All filter operations through the Filter Toolbar are made using the 'bw' (begins with) operator.

How can I set the operation I want to be performed by column?

In this case I want to perfor a 'eq' on the numeric column and a 'cn' on the alphanumeric.

btw, if I use the advanced search dialog everything works correctly.

Thanks!

Here's my implementation:

$('#EntityListGrid').jqGrid({
    url: '<%= ResolveUrl("~/Controls/EntityManager/Controllers/EntitiesController.ashx?method=GridDataList") %>',
    datatype: 'json',
    mtype: 'GET',
    colNames: ['ID', 'Name', 'Actions'],
    colModel: [
    { name: 'EntityID', index: 'EntityID', width: 50, align: 'left', resizable: true, sortable: true, sopt:['eq'] },
    { name: 'Name', index: 'Name', width: 250, align: 'left', resizable: true, sortable: true },
    { name: 'act', index: 'act', width: 75, sortable: false, search: false },
    ],
    pager: $('#EntityListGridPager'),
    rowNum: 10,
    rowList: [10, 20, 30],
    sortname: 'EntityID',
    sortorder: 'desc',
    viewrecords: true,
    imgpath: '',
    caption: 'Entities',
    width: EntityListGridWidth,
    height: 400,
    gridComplete: function () {
        var ids = jQuery("#EntityListGrid").jqGrid('getDataIDs');
        var editImageUrl = '<%=Page.ResolveUrl("~/Controls/EntityManager/Images/edititem.GIF")%>';
        for (var i = 0; i < ids.length; i++) {
            var cl = ids[i];

            ce = "<img src='" + editImageUrl + "'  onclick='EditEntity(" + cl + "); return false;' />";
            ce2 = "<input type='button' value='details' src='" + editImageUrl + "' onclick='EditEntity(" + cl + "); return false;' />";
            $("#EntityListGrid").setRowData(ids[i], { act: ce2 });
        }
    }
}).navGrid('#EntityListGridPager', { search: true, edit: false, add: false, del: false, searchtext: "Search" }, {}, {}, {}, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true });

$('#EntityListGrid').jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false });
Cerbrus
  • 70,800
  • 18
  • 132
  • 147
AlexCode
  • 4,055
  • 4
  • 33
  • 46

2 Answers2

7

you can use sopt property in the corresponding column definition. It can be sopt:['eq'] and sopt:['cn'] in your case. The setting will overwrite the search operator for the selected column only.

The usage of sopt:['eq'] property is sometime really required. For example if you have the column with the option stype:'select', edittype:'select', formatter:'select'.

UPDATED: Correct setting is searchoptions:{sopt: ['eq']} and not sopt: ['eq']. Read the documentation about it.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • I tried that before posting the question here but it didn't work. Inspecting the request I still read: {"groupOp":"AND","rules":[{"field":"EntityID","op":"bw","data":"4"}]} the column is declared like this: { name: 'EntityID', index: 'EntityID', width: 50, align: 'left', resizable: true, sortable: true, sopt:['eq'] } Do I need anything else? Thanks! – AlexCode Feb 05 '11 at 14:49
  • @AlexCode: I suppose that you have problems in the inplementation. Look at this grid. You can easy verify that after the start the request with `"{"groupOp":"AND","rules":[{"field":"Category","op":"eq","data":"1"}]}"` will be send. It is corresponds which corresponds to the `sopt: ['eq']` option of the 'Category' column. – Oleg Feb 05 '11 at 15:15
  • I'm on try/catch mode on this :) I'll paste my implementation on another comment maybe you can see anything without much trouble. Thanks Oleg! – AlexCode Feb 05 '11 at 15:48
  • @AlexCode: It is better to modify your question as to use comments for the code. – Oleg Feb 05 '11 at 15:49
  • @AlexCode: The error is very simple. See the updated part of my answer. – Oleg Feb 05 '11 at 16:12
  • Dumb... Thanks mate. I wasn't understanding that documentation page. I completly missed that searchoption was an object with the properties defined on the grid bellow... it all makes sense now. Once again, thanks for the precious help. :) – AlexCode Feb 05 '11 at 16:46
0

Just to mention if you dont want to lose the other search operands in the footer Search its important to add all other operands in the Array . only the first is used for Toolbarsearch

for phpgrid

$opsmeta = array("cn","eq","bw","ni","in","ne","lt","le","gt","ge","bn","ew","en","nc") ;
$col["searchoptions"] = array("sopt"=>$opsmeta);

Thank you these treat helped me to sort out some search problems

Stedy
  • 7,359
  • 14
  • 57
  • 77
Metacowboy
  • 121
  • 2
  • 4