1

I have jqGrid which is initially empty (I return data from server only when _search is true). This is grid code:

jQuery(gridId).jqGrid({
                    url : '/controller/GetData',
                    height : 100,
                    multiplesearch : true,
                    datatype : "json",
                    mtype : "POST",
                    rowNum : 10,
                    rowList : [ 10, 20, 30 ],
                    sortname : 'LBONumber',
                    sortorder : "desc",
                    viewrecords : true,
                    onSelectRow: jqGridRowSelected,
                    caption : 'DATA',
                    colNames : ["LBO","First name","Adress"],
                    colModel : [{"name":"LBONumber","index":"LBONumber","hidden":false},{"name":"FirstName","index":"FirstName","hidden":false},{"name":"Adress","index":"Adress","hidden":false},
    });

I have text field with id "LBO" and on click of a button I execute this code:

$(gridId).setGridParam({
                            search: true,
                            postData: {
                                'filters':$.param({
                                    'groupOp': 'AND',
                                    'rules': [{ "field": 'LBONumber', "op": 'eq', "data": function () { return $("#LBO").val() } }]
                                })
                            }
                        });

My problem is request body, which is:

_search=true&nd=1306834594225&rows=10&page=1&sidx=LBONumber&sord=desc&filters%5BgroupOp%5D=AND&filters%5Brules%5D%5B0%5D%5Bfield%5D=LBONumber&filters%5Brules%5D%5B0%5D%5Bop%5D=eq&filters%5Brules%5D%5B0%5D%5Bdata%5D=333

It should say ...filters=..., not ...filters%5B... and I don't want to process it on server, it must be a proper way of making this work. I know that this is actually properly serialized object, but I need this my function to work same way as jqGrid's included search, as I already have server-side code done for that case.

Goran Obradovic
  • 8,951
  • 9
  • 50
  • 79

1 Answers1

3

You construct the filters in the wrong way. Instead of usage $.param the value of filters must be JSON encoded (see the documentation) with respect of JSON.stringify for example. The answer contain the corresponding code example.

UPDATED: The definition of postData can be about the following

postData: {
    filters: function () {
        return JSON.stringify(
            { groupOp: "AND", rules: [
                { field: 'LBONumber', op: 'eq', data: $("#LBO").val() }
            ]}
        );
    })
}
Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • bravo! You are genius! :) That is just **exactly** the answer I wanted to get, I used JSON.stringify long time ago, totally forgot about it and knew that I'm missing something but could not remember what :) – Goran Obradovic May 31 '11 at 20:00