how to set postData in jqgrid AFTER it has been constructed?

别说谁变了你拦得住时间么 提交于 2019-11-30 14:19:36
Oleg

You didn't include the definition of jqGrid in your question and we can't see the place where the setGridParam is called. First of all you should use setGridParam after the jqGrid is created, but before the request will be sent. If you will change the postData the next jqGrid request can use the new parameter. So one typically uses

$("#@Model.Id").trigger('reloadGrid', [{page:1}]);

see here.

I suppose that the best option for you will be the usage of function test property of the postData as the function:

$("#@Model.Id").jqGrid({
    // ... other jqGrid parameters ...
    postData: {
        test: function() {
            // the code can by dynamic, read contain of some elements 
            // on the page use "if"s and so on and return the value which 
            // should be posted to the server
            return 233;
        }
    }
    // other jqGrid parameters ...
});

See here for details. In this way you can implement practically any scenario.

By the way if you don't want that jqGrid to send any request to the server till the event is happened you can use datatype:'local' at the initialization time. Then if you want that the grid should be filled you can use setGridParam to change the datatype from 'local' to 'json' (or 'xml') and call .trigger('reloadGrid',...).

user1761013
$("#grid id").setGridParam({ postData: {data:dataval} });
$("#grid id").trigger('reloadGrid', [{page:1,data:dataval}]);ntn

Here is the method i used

postData: { 'testKey': function () { return 'testvals'; } },
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!