0

I am trying to have the page load with a pre-defined filter already applied to the grid.I've tried the following code without success.

$("table#worksheetsTable").jqGrid("setGridParam", {
            gridComplete: function() {
                //tried to set all this here too
            },
            postData: { searchField: "ScreeningNumber", searchString: "8882", searchOper: "bw" },
            search: true
        });

I've also tried $("table#worksheetsTable").jqGrid("setGridParam", {search: true}) outside of the first call as well. When I compare the form values generated with this and with what occurs when i click on the filter myself with Fiddler, they look the same.

UPDATE: Every example of this I've found has to do with multiple filters... I've finally found this answer from Oleg that explains (i think) that doing a single filter is different than doing multiple filters. I will update this and mark the answer once I try this.

Community
  • 1
  • 1
diegohb
  • 1,857
  • 2
  • 16
  • 34

1 Answers1

1

add trigger('reloadGrid') after changing grid parameters like so:

$("table#worksheetsTable").jqGrid("setGridParam", {
            gridComplete: function() {
                //tried to set all this here too
            },
            postData: { searchField: "ScreeningNumber", searchString: "8882", searchOper: "bw" },
            search: true
        }).trigger('reloadGrid');

editing after the ensuing discussion:

could be an issue of the parameter names you are using according to the documentation of the helper you are using

make sure the request parameter names you have in your mvc action method match whatever you set in your postdata, also the searchoperation enum is supposed to contain 'Bw' not 'bw' - depends on whether the helper uses a case insensitive method to parse the enum.

link to documentation here

Pete_ch
  • 1,301
  • 2
  • 28
  • 39
  • 1
    or just use the easier $("table#worksheetsTable").jqGrid({all your parameters here}); instead of using setGridParam; if as I understand it this is the 1st load of the grid – Pete_ch Mar 19 '12 at 01:27
  • I've tried this as well... and as far as your comment, I would but I'm actually using an MVC helper method to generate all that from Lib.Web.Mvc [link](http://tpeczek.codeplex.com/releases/view/62741) and when it generates the initial jqGrid initialization it still doesnt work.. – diegohb Mar 19 '12 at 01:40
  • mybe its not a good idea to mix client side manipulation and a 3rd party server side generated grid;maybe the helper uses soem custom handling methods/variables; is there a sever side method for the helper to set grid params or even to reload the grid? – Pete_ch Mar 19 '12 at 02:11
  • lets see all your server side handling of the request parameters in your action method – Pete_ch Mar 19 '12 at 02:25
  • this is what it generates for the jqgrid init, `postData: {"searchField":"ScreeningNumber","searchString":"854","searchOper":"bw","search":true},rowNum: 15` i've had it generate key/value like `searchField: "ScreeningNumber"` too.. still didn't work. As far as I'm concerned I'm doing the same thing that [this](http://www.ok-soft-gmbh.com/jqGrid/MultisearchFilterAtStart.htm) is doing... except I need a single filter not multiple filters. – diegohb Mar 19 '12 at 02:36
  • what I mean is how is your mvc app handling the filtering? could your issue be a server side issue? – Pete_ch Mar 19 '12 at 03:00
  • @diegohb: Do you use `postData: {"searchField": "ScreeningNumber", "searchString": "854", "searchOper": "bw", "search"‌​: true}, rowNum: 15` or `postData: {"searchField": "ScreeningNumber", "searchString": "854", "searchOper": "bw"}, "search"‌​: true, rowNum: 15`? The `search: true` should be *not* the part of `postData`. – Oleg Mar 19 '12 at 06:44
  • I've tried including it and excluding it with no luck.. Do I need to extend postData with original postData obj ? – diegohb Mar 19 '12 at 17:58