Telerik RadGrid CustomSorting 无需访问数据库?
我尝试在 Telerik 论坛上发帖,但现在每次我尝试打开我的帖子时,我都会得到 “哎呀... 我们的服务器似乎有问题。” 所以我在这里发布了这个问题。
我对 Telerik 和 RadGrid 还很陌生。我正在尝试修改现有项目,因为客户需要自定义排序。有一个数据字段可能包含数字或文本,因此它是字符串类型,但有时必须将其排序为数字。所以我去了这个链接:
http://demos .telerik.com/aspnet-ajax/grid/examples/programming/sort/defaultcs.aspx
和 http://www.telerik.com/help/aspnet-ajax/grdapplycustomsortcriteria。 html
示例显示:
“打开自定义排序后,RadGrid 将显示排序图标,但实际上不会对数据进行排序。” 但添加AllowCustomSorting来禁用默认排序似乎还不够。
在实现 SortCommand 时,我注意到我必须做 e.取消= true;
因为否则会发生默认排序。为什么文档和示例中都没有提到这一点?
但主要问题是 - 在 SortCommand 内部,我的 RadGrid 已经加载了所有项目。那么有没有办法对它们进行排序以避免访问数据库呢?我尝试访问“对象源,GridSortCommandEventArgs e”的各种 Items 属性,但所有 Items 都是只读的,因此我无法对它们进行排序并附加回 RadGrid。
感谢您的任何想法。
I tried to post on Telerik forum, but now each time I try to open my thread, I get
"Oops...
It seems there was a problem with our server."
So I posted this question here.
I am pretty new to Telerik and RadGrid. I am trying to modify existing project because client needs custom sorting. There is a data field which may contain numbers or text so it is a string type but sometimes it has to be sorted as numbers. So I went to this link:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/sort/defaultcs.aspx
and
http://www.telerik.com/help/aspnet-ajax/grdapplycustomsortcriteria.html
The example says:
"With custom sorting turned on, RadGrid will display the sorting icons but it will not actually sort the data."
but it seems it is not enough to add AllowCustomSorting to disable default sorting.
When implementing SortCommand, I noticed that I have to do
e.Canceled = true;
because else default sorting occurs. Why this is not mentioned in the documentation nor example?
But the main question is - inside of SortCommand my RadGrid already has all items loaded. So is there any way to sort them to avoid hitting database? I tried accessing various Items properties of both "object source, GridSortCommandEventArgs e", but all Items are read-only, so I cannot sort them and attach back to the RadGrid.
Thanks for any ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在objectDatasource的OnSelecting事件中设置sortExpression并在SelectMethod中使用它。
这样您就可以执行自定义排序并将数据传递到 RadGrid。
希望这有帮助。
You can set the sortExpression in the OnSelecting event of the objectDatasource and use it in the SelectMethod.
This way you can perform custom sort and pass on the data to the RadGrid.
Hope this helps.
这是我使用的一些代码的示例,但未访问数据库。我将 MVC 3 与 Razor 视图引擎一起使用。请注意 Ajax 绑定。不要忘记使用 Telerik.Web.Mvc.UI 添加并使用 [GridResult] 注释控制器中的“Post”方法,并返回 GridModel 以获取 Json 结果集。
这里是index.cshtml(razor引擎),关键是Ajax绑定。
Here is an example of some code I use that does not hit the database. I'm using MVC 3 with the Razor view engine. Notice the Ajax binding. Don't forget to add using Telerik.Web.Mvc.UI and annotate the "Post" methods in your controller with [GridResult] and to return GridModel to get the Json resultset.
Here is the index.cshtml (razor engine), the key is the Ajax binding.