javascript Telerik radGrid - 在排序/分页/过滤器上保持客户端状态
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6044259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
telerik radGrid - persist client state on sort/paging/filter
提问by kralco626
Even in this ajax examplewhich I really like the look of, when ever the top level grid is sorted the "state" of what you were doing "disappears"
即使在这个 我非常喜欢的ajax 示例中,当顶级网格被排序时,你正在做的“状态”“消失”
For example,
例如,
Open the first person's row (Nancy Davolio) so you can see the Sales grid
Sort by Order Total in the Sales grid
Sort by Birth Date in the top level grid
Nancy Davoilo should now be second. Open her row.
The sales grid is no longer sorted by Order Total
打开第一个人行 (Nancy Davolio),以便您可以看到 Sales 网格
在销售网格中按订单总额排序
在顶层网格中按出生日期排序
Nancy Davoilo 现在应该排在第二位。打开她的行。
销售网格不再按订单总额排序
This may seem trivial, or that i'm being picky; However:
这可能看起来微不足道,或者我很挑剔;然而:
If I have some text box(or some other type of method of accepting user input) on the sales grid, I would assume that this would get destroyed when sorting the top level grid. I would also think that even if I had this input on the top level grid, that sorting the top level grid (or filtering if there were filters) would destroy this input.
如果我在销售网格上有一些文本框(或某种其他类型的接受用户输入的方法),我会假设在对顶级网格进行排序时会被破坏。我还认为,即使我在顶级网格上有这个输入,对顶级网格进行排序(或过滤,如果有过滤器)会破坏这个输入。
It seems that even paging destroys this.
似乎即使分页也会破坏这一点。
The desired behavior would be for sorting and paging not just "appear" to be done client side because it's using an ajax request, but to ACTUALLY be done client side. Meaning that the actual rows of the grid are literally sorted(filtered, paged, etc.) client side so that any client side changes such as adding text to a text box, adding a css class to an object, [or in a more complex example adding a reference to a javascript object to an object via Jquery: $("#div1").data("object",someObject)
would persist after sorting, paging and filtering.
所需的行为是排序和分页不仅“看起来”在客户端完成,因为它使用 ajax 请求,而是实际上在客户端完成。这意味着网格的实际行按字面排序(过滤、分页等)客户端,以便任何客户端更改,例如向文本框添加文本,向对象添加 css 类,[或更复杂的示例通过 Jquery 向对象添加对 javascript 对象的引用:$("#div1").data("object",someObject)
将在排序、分页和过滤后持续存在。
Is there a way to make this happen?
有没有办法做到这一点?
Am I making what i'm looking to do clear? If not i'm happy to clarify.
我是否把我想做的事情说清楚了?如果不是,我很乐意澄清。
Additional Notes: I would think the client side performance hit would be minimal to do something like this as long as there were not a very large number of rows. In fact there would be a lot less work on the server in recreating all of the records, repeated calls to the server/database and as in my example at the top the subPages would only need to be created once rather than twice.
附加说明:只要行数不是很多,我认为执行此类操作对客户端性能的影响很小。事实上,服务器上重新创建所有记录、重复调用服务器/数据库的工作会少得多,就像我在顶部的示例中那样,子页面只需要创建一次而不是两次。
回答by Kevin Babcock
Take a look at the HierarchyLoadMode property of the MasterTableView. The demo you reference is using HierarchyLoadMode.ServerOnDemand
which, according to Telerik's documentation, means that ViewState only maintains the state of the visible items. Therefore, when a details grid is collapsed you will lose its state (e.g. a sort order, page number, etc).
查看 MasterTableView 的 HierarchyLoadMode 属性。您引用的演示正在使用HierarchyLoadMode.ServerOnDemand
,根据Telerik 的文档,这意味着 ViewState 仅维护可见项的状态。因此,当详细信息网格折叠时,您将丢失其状态(例如排序顺序、页码等)。
There are other modes. You can choose HierarchyLoadMode.ServerBind
which maintains ViewState for all detail tables but requires a PostBack to expand a detail table. The HierarchyLoadMode.Client
renders the MasterTableView and all DetailTables and items are expanded/collapsed on the client - no PostBack required. Either of those modes should also maintain the sort order and other state related to the detail tables.
还有其他模式。您可以选择HierarchyLoadMode.ServerBind
哪个维护所有明细表的 ViewState,但需要 PostBack 来展开明细表。该HierarchyLoadMode.Client
呈现MasterTableView和所有DetailTables和项目展开/折叠在客户端上-无需回发。这些模式中的任何一种还应该维护与详细表相关的排序顺序和其他状态。
I hope that helps answer your question.
我希望这有助于回答你的问题。
回答by Dick Lampard
I recently got a reply from the Telerik support that their AJAX grid supports client binding out-of-the-box with sorting, paging and filtering with flat structure only (as in this demo).
我最近收到 Telerik 支持的回复,他们的 AJAX 网格支持开箱即用的客户端绑定,仅使用平面结构进行排序、分页和过滤(如本演示中所示)。
For your case you may have two options:
对于您的情况,您可能有两种选择:
- extend the example with grid settings persister - http://demos.telerik.com/aspnet-ajax/grid/examples/programming/savinggridsettingsonperuserbasis/defaultcs.aspx
- implement custom solution to simulate hierarchy with client binding as presented in this blog post.
- 使用网格设置持久器扩展示例 - http://demos.telerik.com/aspnet-ajax/grid/examples/programming/savinggridsettingsonperuserbasis/defaultcs.aspx
- 实现自定义解决方案以模拟具有客户端绑定的层次结构,如本博客文章中所述。