问题分页的jqGrid的Ajax调用 [英] issue with ajax call on paging in jqgrid

查看:127
本文介绍了问题分页的jqGrid的Ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建造了 jqGrid的使用Struts2的-的jQuery jqGrid的插件。一切是伟大的工作,除了页面

I have constructed the jqgrid using struts2-jquery-jqgrid plugins. Everything is working great except paging,

问题::当我在寻呼机点击下一步按钮,我想执行一些Ajax为基础的操作。我使用的 onPaging(jqGrid的方法) onPagingTopics主题(jqGrid的-插件)套​​住的页面事件。我成功,但在这里实际的问题开始得到这个寻呼事件。当我点击下一步按钮,我陷使用onPagingTopics 主题,这个事件里面我叫一个Ajax请求,但这个AJAX请求完成之前,在 jqGrid的自动获得的重新加载,这就是为什么我不能在 AJAX调用 successsfully。为什么发生这种情况,以及如何为限制 jqGrid的从重装。

Problem : When I click on the next button in pager, I want to perform some ajax-based operation. I am using onPaging(jqgrid method) or onPagingTopics topics(jqgrid-plugins) to trap the paging event. I get this paging event successfully but from here actual problem starts. When I click on next button, I trap the paging event using onPagingTopics Topics, inside this event I call an ajax-request, But before this ajax-request is completed , the jqgrid is automatically getting reload, and that is why I can not make the ajax-call successsfully. why this is happening and how to restrict jqgrid from reload.

注意:我的jqGrid的越来越重新加载致电网址我这个网格内指定。您可以检查电网这里如何加载JSON的jqGrid的

Note: My jqgrid is getting reload by calling the url I have specified inside this grid. You can check the grid here how to load json in jqgrid

这就是我的陷阱寻呼事件:

$.subscribe('paging',function(event,data) 
 {
   var search_string=$("#searchString").val();
   var search_field=$("#searchField").val();        
$.ajax({
         url:"adminJsontable?searchString="+search_string,
         dataType:"json",
         success: function(jsondata,stat)
          {
            var mgrid = jQuery("#gridtable")[0];
            mgrid.addJSONData(jsondata);
          }
       });
  });

更新部分:

     $.subscribe('before',function(event,data) 
  {
    var grid = jQuery("#gridtable"); 
    grid.jqGrid('setGridParam',{url:"adminJsontable?searchString="+"neo"});
  });

这是我如何改变URL,但它不工作。 这样我可以得到这样的准备,完整的,成功的任何事件。请指引我现在西隧我必须做的。

This is how I am changing the url, but its not working. This way I can get any events like ready, complete,success. Please guide me now wht I have to do.

注意:我可以使用任何方法或用于jqGrid的,但不知道任何事件如何使它

Note : I can use any methods or any events which is used in jqgrid but dont know how to make it.

推荐答案

我认为有只是误解jqGrid的是如何工作的。如果用户选择另一个页面 jqGrid的使得AJAX请求每个默认服务器。如果您需要包括在请求中可以使用服务器的其他自定义过滤器 POSTDATA (见的答案)。例如,您可以执行以下

I think that there are just misunderstanding how jqGrid works. If the user choose another page jqGrid makes ajax request to the server per default. If you need to include additional custom filter in the request to the server you can use postData (see the answer). You can do for example the following

$("#grid").jqGrid({
    url: "adminJsontable",
    postData: {
        searchField: function () {
            return $("#searchField").val();
        },
        searchValue: function () {
            return $("#searchString").val();
        }
    },
    ... // other options which you use
});

我不使用Struts自己,但我相信你能改写自己的内部的Struts的使用。

I don't use Struts myself, but I am sure that you can rewrite yourself for the usage of inside Struts.

以上code将发送额外的参数 searchField searchValue 上的每个请求的服务器,包括分页排序等,因此,如果用户在 #searchField 输入一些数据和 #searchString 然后该数据将由您的服务器code予以考虑。

The above code will send additional parameters searchField and searchValue on every request to the server including paging sorting etc. So if the user enter some data in #searchField and #searchString then the data will be considered by your server code.

更新时间::如果你不知道如何指定 POSTDATA 的情况下使用struts2的-的jQuery jqGrid的插件,你一定还能够以包括在HTML页一些JavaScript文件。如果包括

UPDATED: If you don't know how to specify postData in case of usage struts2-jquery-jqgrid plugin you must be still able to include some JavaScript file on the HTML page. If you includes

$.extend(true, $.jgrid.defaults, {
    postData: {
        searchField: function () {
            return $("#searchField").val();
        },
        searchValue: function () {
            return $("#searchString").val();
        }
    }
});

您将能够重新定义默认值 {} POSTDATA 的jqGrid的来,我建议值参数以上。重要的是,上述code应执行的的jaGrid被创建。如果你只能后执行JavaScript code 的网格创建您可以执行以下code

you will be able to redefine default value {} of postData parameter of jqGrid to the value which I suggested above. It's important that the above code should be executed before jaGrid is created. If you can execute JavaScript code only after the grid is created you can execute the following code

$.extend(true, $("#gridtable").jqGrid("getGridParam", "postData"),
    {
        searchField: function () {
            return $("#searchField").val();
        },
        searchValue: function () {
            return $("#searchString").val();
        }
    }
});

这篇关于问题分页的jqGrid的Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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