分页时如何保留 Telerik MVC 网格列顺序和大小?
我有一个 Telerik ASP.NET MVC 网格,它使用服务器数据绑定并启用了列大小调整和重新排序。如果我手动重新排序或调整列大小,然后使用网格分页器跳转到网格的另一页,则列大小和顺序将恢复为默认设置。分页时保留用户对列大小和顺序的更改的最佳方法是什么?
在 Telerik 演示网站上,我发现了一个示例,该示例使用带有 AJAX 数据绑定的隐藏表单字段,但据我所知,这不适用于绑定 HTTP GET 的服务器。我开始使用 cookie 而不是隐藏的表单字段,但它开始变得混乱,我正在寻找有关替代方法的反馈。
I have a Telerik ASP.NET MVC grid that uses server data binding and has column resizing and reordering enabled. If I manually re-order or re-size the columns and then use the grid pager to jump to another page of the grid, the column sizes and order revert back to the default settings. What is the best way to preserve user changes to the column size and order when paging?
On the Telerik demos site I found an example that uses hidden form fields with AJAX data binding, but as far as I know that won't work for the server binding HTTP GETs. I started down the path of using cookies instead of hidden form fields, but it started getting messy and I was looking for feedback on alternative approaches.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将列宽作为模型的一部分或使用 ViewBag(或 ViewData,如果您使用的是 MVC 2)传递到网格,
然后您可以使用以下方法设置列宽:
- 或 -
然后您可以使用通过
OnColumnResize
事件回调(当用户调整网格列大小时会引发该回调)如果您使用会话状态,则还可以将值存储在会话变量中(如果它们要在整个过程中持续存在)用户的会话。
You could pass the column widths down to the grid either as part of your model or with ViewBag (or ViewData if you're using MVC 2)
You can then set your column widths using:
- or -
You can then update the values using a callback via the
OnColumnResize
event (this is raised when a grid column is resized by the user)If you're using session state, you could also store the values in session variables if they are to persist throughout the user's session.