beforeRequest事件jqGrid:在调用url之前设置jqGrid页面 [英] beforeRequest event jqGrid: set jqGrid page before url is called

查看:145
本文介绍了beforeRequest事件jqGrid:在调用url之前设置jqGrid页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在对URL的GET请求之前在jqGrid中设置页面变量...

I am trying to set the page variable in jqGrid before the GET request to the URL...

        jQuery("#frTable").jqGrid({                
            cmTemplate: { sortable: false },
            caption: '@TempData["POPNAME"]' + ' Population',
            datatype: 'json',                
            mtype: 'GET',
            url: '/Encounters/GetAjaxPagedGridData/',

我已经尝试了各种各样的方法,无论我尝试什么,我似乎都无法使它正常工作... 我已经尝试了各种各样的方法,"sort-of"工作的唯一方法就是订阅LoadComplete事件,就像这样……

I have tried all sorts of things and I can't seem to get this to work no matter what I try... I have tried all sorts of things and the only thing that 'sort-of' worked was subscribing to the LoadComplete event like so...

            loadComplete: function() {
                if ((rowFromTemp != "") && (pageFromTemp != "")) {
                    setTimeout(function () {
                    $("#frTable").trigger("reloadGrid", [{page: pageFromTemp, rowNum: rowFromTemp}]); 
                    }, 50);
                }
            },

我唯一遇到的问题是它不断更新.不知道为什么会这样.我唯一想到的是,我正在以某种方式循环使用超时功能...

the only problem that I had with that was that it was constantly updating. Not sure why that would happen. The only thing I figure there is that I am somehow looping with my timeout function...

我尝试订阅其他几个请求,但每个请求似乎都失败了.我感到最有希望的是beforeRequest事件.这是我目前拥有的...

I have tried subscribing to a couple of other requests but each of those seems to fail. The most promising I felt was the beforeRequest event. This is what I currently have...

            beforeRequest: function() {
                if ((rowFromTemp != "") && (pageFromTemp != "")) {
                    $("#frTable").setGridParam([{ page: pageFromTemp, rowNum: rowFromTemp }]);                        
                    }
            },

它不在乎我将变量设置为什么,它只是在第1页上打开而已.
现在,我在这里可以将数据设置为本地",这意味着您必须重新加载网格才能获取任何数据.

It doesn't care what the heck I set the variables to, It just opens up on page 1 NO MATTER WHAT.
Now, I here that you can set the data to 'local' and that means that you have to reload the grid to get any data.

但是我希望在用户第一次打开数据时加载数据.我正在尝试设置页面,以便用户在我的编辑屏幕上编辑一行后,当他单击保存"时,他将被带回到他刚才所在的页面.不是第一页.如您所知,这会让用户感到沮丧.

But I want the data to load when a user first opens it up. I am trying to set the page so that after a user edits a row with my edit screen, when he hits save, he will be taken back to the page that he was just on. Not the first page. As you know, that would be very frustrating for a user.

更新

好吧...我在我的beforeRequest事件中放了一个警报,并在加载网格之前触发了该警报.在url部分中调用的操作中设置一个断点,可以告诉我在实际发出请求之前便已调用了警报.这就是我所希望的.我只需要弄清楚如何正确设置页面变量即可.

Ok... I put an alert in my beforeRequest event, and it fired before my grid loaded. Setting a break point in my action that is called in the url section tells me that the alert is called before I actually make the request. Which is what I am hoping for. I just need to figure out how to properly set the page variable.

更新2 好的.我设置了变量,并让我的警报告诉我变量确实已设置...

UPDATE 2 Ok. I set the variable, and I had my alert show me that the variable was indeed set...

            beforeRequest: function() {
                if ((rowFromTemp != "") && (pageFromTemp != "")) {
                    this.p.page = pageFromTemp;
                    alert("This is what the page is: " + this.p.page + ";  And this is what I want it to be: \n" + pageFromTemp + " How do I get it there \n");

但是,它仍然加载第一页吗?所以很明显,它再次被覆盖.为什么?如何永久设置此设置.

However, it still loads the first page? So obviously, it is getting overridden again. Why? How can I set this permanently.

推荐答案

我遇到了同样的问题,但是我在BeforeRequest函数上做到了这一点:

I had the same problem but I got it working doing this on the BeforeRequest function:

$('#GRID_ID').jqGrid('setGridParam', { postData: { page: 4} });

这篇关于beforeRequest事件jqGrid:在调用url之前设置jqGrid页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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