0

I have following setup. I have a view, in asp.net MVC, which loads without any data. On click of a button, we setup a jqgrid (call (#grid).jqGrid) which retrieves data from a server. But, we also want to send some parameters. These parameters will be used as filters on the server side before returning json data for jqgrid. How to do this?

`$('#getrecords').click(function (e) {
        e.preventDefault();
        debugger;
        jQuery("#records").jqGrid({
            url: '/Test/Data/',
            datatype: 'json',
            mtype: 'POST',
            ajaxGridOptions: { contentType: "application/json" },
            colNames: ['Id', 'Name'],
            colModel: [
      { name: 'Id', index: 'Id', width: 50, align: 'left' },
      { name: 'Name', index: 'Name', width: 300, align: 'left'}],
            pager: jQuery('#pager'),
            rowNum: 10,
            rowList: [10, 20, 50],
            viewrecords: true,
            caption: 'My first grid',
            postData: {
                myname: function () { $('#myname').val(); },
                childname: function () { $('#child').val(); }
            }


        });
    });

`

ruskin
  • 469
  • 9
  • 17
  • You can use `postData` parameter of jqGrid. Look [here](http://stackoverflow.com/questions/2928371/how-to-filter-the-jqgrid-data-not-using-the-built-in-search-filter-box/2928819#2928819) for example. – Oleg Sep 20 '11 at 23:28
  • I did use postData but not getting data on server. – ruskin Sep 21 '11 at 13:51
  • 1
    You accepted the answer of RoccoC5 who also suggest you `postData`, but write that you do have problems with the usage of `postData`. Is your problem is solved or not solved? If you have any problem you should include code where the problem exists and which shows how you use `postData`. – Oleg Sep 21 '11 at 17:51
  • posted the code. please check – ruskin Sep 23 '11 at 01:37

1 Answers1

0

You can use the grid's postData option to define parameters that should be passed to the server on each request:

postData: { param1: 'value1', param2: 'value2', etc... }

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options

RoccoC5
  • 4,185
  • 16
  • 20