构造后如何在jqgrid中设置postData? [英] how to set postData in jqgrid AFTER it has been constructed?

查看:485
本文介绍了构造后如何在jqgrid中设置postData?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从传递给视图的模型类生成jqgrid.我开始构建并工作了jqgrid.但是,我想在调用helper创建jqgrid之后,在该视图的脚本中的一个视图上使用jqGrid来设置postData,而不必更改创建jqgrid的整个局部视图.

I generate my jqgrid from model class which I pass into view. I get constructed and working jqgrid. However, I want to set postData on one view, where I use jqGrid, from script in that view, after I call helper for creating jqgrid, without having to change whole partial view which creates jqgrid.

我尝试跑步

$("#@Model.Id").jqGrid('setGridParam', { postData: { test: 233} });

$("#@Model.Id").setGridParam({ postData: { test: 233} });

,但没有错误或任何结果.如果我在jqgrid参数中设置postData(在构造它的局部视图中,它将起作用.

but without error or any result. If I set postData in jqgrid parameters (in partial view where it is constructed, it works.

我还检查了网格是否存在,已添加

I also checked that grid exists, added

console.log($("#@Model.Id").size());

在第一行之前,它显示1.

before the first line, and it shows 1.

更新:这个.setGirdParam函数开始为我运行的原因没有明显的原因,因此,如果有人可以提供一些见识来阻止它运行,我将接受答复. 谢谢

UPDATE: This .setGirdParam function started to work for me for no apparent reason, so I will accept answer if someone can give some insight what can prevent this from working. Thanks

推荐答案

您没有在问题中包括jqGrid的定义,我们也看不到 setGridParam所在的位置叫.首先,应该在创建jqGrid之后使用setGridParam ,但是将之前发送请求.如果您要更改postData 下一个,则jqGrid请求可以使用新参数.所以通常使用

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}]);

请参见此处.

我认为对您来说最好的选择是将postDatatest函数属性用作函数:

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.

如果您不希望jqGrid在事件发生之前向服务器发送任何请求,可以在初始化时使用datatype:'local'.然后,如果希望填充网格,则可以使用setGridParamdatatype'local'更改为'json'(或'xml'),然后调用.trigger('reloadGrid',...).

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',...).

这篇关于构造后如何在jqgrid中设置postData?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆