问题描述
我有一个按钮 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 标头 选择.例如,您可以使用 max-age缓存控制"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
参数的发送以及任何服务器中包含的时间戳要求.执行完这些步骤后,jqGrid 使用的所有 ajax 请求都会在时间间隔(60 秒)内从本地缓存中获取.
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(实体标签).这是我最喜欢的策略,但它的实现相对复杂(参见 有关在使用 ASP.NET MVC 2 时保留过滤选项的更好方法的指南 和 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:
- 在定义 jqGrid 参数的表单中在同一页面上创建与按钮和其他过滤器相同的网格(参见 如何不使用内置搜索/过滤框过滤jqGrid数据).
- 重绘"页面 与
jQuery.Remove()
或jQuery.Empty()
和新的相关的表单>ajax
请求.例如jQuery("body").Empty()
或jQuery("div#main").Empty()
where<div id="main">
位于主体顶部的某个位置.然后你可以用像jQuery("body").load("newPage.htm")
或jQuery("div#main").load("newPage.jsp")
.
- 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).
- "Repainting" the page with the form with respect of
jQuery.Remove()
orjQuery.Empty()
and newajax
request. For example withjQuery("body").Empty()
orjQuery("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 likejQuery("body").load("newPage.htm")
orjQuery("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 缓存网格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!