jqGrid缓存网格数据 [英] jqGrid caching the grid data

查看:138
本文介绍了jqGrid缓存网格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个onclick按钮,应该转到另一个包含jqGrid的页面.但是,如果用户要查看数据,则应将其缓存并显示而不是调用服务器.默认情况下缓存,但是jqGrid ...如何缓存它?

I have a button onclick it should go to a another page containing jqGrid..but if user want to go and see the data it should be cached and show instead of making a call to the server.... form values were cache by default but jqGrid ...how to cache it?

推荐答案

可以实现数据缓存,但这并不容易.您必须在服务器端基于缓存策略定义一些HTTP标头选择.例如,您可以使用以下网址的最大年龄 "Cache-Control" HTTP标头,如

The Caching of data can be realized but it is not easy. You have to define on the server side some HTTP headers based on the caching strategy choosed. For example you can use max-age of the "Cache-Control" HTTP header like

Cache-Control: max-age=60

这意味着应该在60秒钟内在客户端上缓存服务器响应.如果打算使用此功能,则必须定义jqGrid的其他参数prmNames:{nd:null},它将删除带有任何服务器请求中包含的时间戳的nd参数的发送.完成此步骤后,将在时间间隔(60秒)内从本地缓存中获取jqGrid使用的所有ajax请求.

which means, that the server response should be cached during 60 sec on the client. If you plan to use this you have to define additional parameter prmNames:{nd:null} of jqGrid, which will remove sending of nd parameter with the timestamp included in any server request. After doing this steps all ajax requests used by jqGrid will be get from the local cache during the time interval (60 sec).

ETags (实体标签).这是我最喜欢的策略,但是它的实现相对复杂(请参阅 Sql事务的并发处理以获取详细信息).

The implementation of the server side caching with strategy more complex as a fixed caching time is possible with respect of ETags (Entity Tags). It is my favorite strategy, but its implementation is relatively complex (see Guidance on a better way to retain filtering options when using ASP.NET MVC 2 and Concurrency handling of Sql transactrion for details).

如果由于某些原因您将无法使用数据缓存的方式,我建议您选择以下两种变体:

If the way with caching of data you will be not able to use (because of some reasons) I would recommend you as an alternative following two variants:

  1. 在与定义jqGrid参数的表单中的按钮和其他过滤器相同的页面上创建网格(请参阅.例如,使用jQuery("body").Empty()jQuery("div#main").Empty()时,其中<div id="main">位于身体顶部.然后,您可以使用jQuery("body").load("newPage.htm")jQuery("div#main").load("newPage.jsp")之类的调用来填充页面正文(或id为"main"的div).
  1. creating the grid on the same page as the buttons and other filters from the form which defines jqGrid parameters (see How to filter the jqGrid data NOT using the built in search/filter box).
  2. "Repainting" the page with the form with respect of jQuery.Remove() or jQuery.Empty() and new ajax request. For example with jQuery("body").Empty() or jQuery("div#main").Empty() where <div id="main"> is somewhere on top of the body. Then you can fill the page body (or div with id="main") with the call like jQuery("body").load("newPage.htm") or jQuery("div#main").load("newPage.jsp").

这些替代方法的优点在于,您将停留在同一页面上,并且可以使用所有JavaScript数据.例如,如果网格使用"loadonce:true"参数,则可以从'data'参数中获取旧的jqGrid数据,然后使用该数据值作为新jqGrid的'data'参数来创建新的jqGrid.

The advantage of these alternatives is that you will stay on the same page and all JavaScript data can be used. You can for example get old jqGrid data from the 'data' parameter if your grid use "loadonce:true" parameter and then create new jqGrid using the data value as the 'data' parameter of the new jqGrid.

这篇关于jqGrid缓存网格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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