本文介绍了对jqgrid列进行排序时,有什么方法可以保留当前页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jqgrid包含几个页面.当我对任何列进行排序时,页面将重置为第一列.

My jqgrid contains several pages. When I sort any column the page resets to first.

(对于filterToolbar也正确,即调用$(#my-grid")[0] .triggerToolbar();)

(That's right also for filterToolbar i.e. after calling $("#my-grid")[0].triggerToolbar();)

排序/过滤后有什么方法可以保留我的当前页面吗?

Is there any way to keep my current page after sorting/filtering ?

实际上我的问题要复杂一些.

Actually my problem is a little more complicated.

我将jqgrid首选项(rowNum,页面,过滤器等)保存到cookie.第一次加载页面时,我会加载偏好设置.我使用了Mark B的答案中的技术(请参见 jqGrid筛选器工具栏初始默认值 )填充我的过滤器默认值.

I save jqgrid preferences(rowNum, page, filters etc..) to the cookie.When I load the page first time I load the prefs.I use the technique from Mark B's answer (see jqGrid Filter Toolbar initial default value) to populate my filter default values.

问题:在这种情况下,页面始终设置为第一个.(由于triggerToolbar调用),即它不保存状态.

The problem: in that case page always sets to the first.(because of triggerToolbar calling) i.e. it doesn't save state.

推荐答案

我不太了解您的要求.例如,如果用户在第二页上看到了一些行,然后用户单击了列标题以对列进行排序,则将对网格进行排序.用户以前看过的数据可以在任何页面上.因此,我不明白您为什么要保留当前页面,该页面绝对会显示以前显示的其他数据.

I don't quite understand your requirement. If the user has seen some rows on the second page for example and then the user has clicked on the column header to sort the column the the grid will be sorted. The data which the user have seen before can be on any page. So I don't understand why you want hold the current page which will show absolutely another data as it showed before.

如果您确实需要保留页面,则可以通过以下方式进行.在loadComplete内部,可以保存page参数的值.在onSortCol事件处理程序内部,该值将已经更改为1,但是您可以将其更正为之前保存的值.我没有对此进行测试,但我认为它应该可以工作.

If you do need to hold the page you can do this in the following way. Inside of the loadComplete you can save the value of page parameter. Inside of onSortCol event handler the value will be already changed to 1, but you can correct it to the value which you saved before. I didn't tested this, but I think it should work.

已更新:现在,我认为我了解您的原始问题.我认为您应该选择此处或.您需要的只是将postData值保存在cookie中,并且如果filters不为空(或其他过滤器参数取决于您使用的选项),则设置jqGrid的search:true参数.这样,您不仅应该能够还原过滤器,而且还可以还原page值.最终的解决方案可能取决于jqGrid参数和所使用的filterToolbar参数.因此,您将遇到实现问题,应包含更多使用的代码.

UPDATED: Now I think I understand your original problem. I think you should choose another way described here or here. What you needs is just to save in the cookie the postData value and to set search:true parameter of jqGrid if the filters is not empty (or other filter parameter depend on the options which you use). In the way you should be able to restore not only the filter, but additionally the page value. The final solution can a little depend from jqGrid parameters and the parameters of filterToolbar which you use. So it you will have implementation problem you should include more code which you use.

这篇关于对jqgrid列进行排序时,有什么方法可以保留当前页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 00:28