如何根据上一页选择过滤 Telerik 网格
我想做的:-
索引页面将有一个类别下拉菜单,选择 1 然后提交,重定向到 telerik 网格页面,所有记录都来自所选类别的大表。
例如,宠物商店,商店有哪种类型的宠物的下拉列表,然后在下一页上的网格中填充了商店今天可用的该类型的所有宠物。
已经对日期过滤器进行了排序,因为它已应用于数据绑定。
数据库是通过 edmx 连接的,它有 2 个没有关系的表,但有一个类别/宠物表,其中详细介绍了每个类别/宠物,然后有一个记录表,其中有一个类别/宠物列,其中 2表有一个共同的字段。
我一直试图通过使用 ViewData 来实现这一点,它对于下拉 <%: Html.DropDownList("category", (SelectList)ViewData["CategoryList"])%> 效果非常好。但无法填充下一页上的网格。
所以有点像 http://demos.telerik.com/aspnet-mvc/grid/selectionserverside 但如果可能的话,使用下拉菜单并跨 2 页。
What I'm trying to do:-
Index page would have a dropdown of say categories, select 1 then submit, redirected to telerik grid page with all records kept from a big table of selected category.
so for example pet store, dropdown for which type of pets the store has then on next page a grid is populated with all pets of that type which the store has available today.
already got the date filter sorted since that's applied to the databind.
database is connection via an edmx, it has 2 table with no relationships but there is say a category/pet table which goes into details for each category/pet and then there is a record table which has a category/pet column of which the 2 tables have that single field incommon.
I have been trying to get this to work by using ViewData which works perfectly fine for the drop down <%: Html.DropDownList("category", (SelectList)ViewData["CategoryList"])%> but fails to populate the grid on the next page.
so something sorta like http://demos.telerik.com/aspnet-mvc/grid/selectionserverside but if possible with a dropdown and across 2 pages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的事情,所以我只是使用 jQuery 来获取每个页面的数据(将 #category 替换为类别下拉列表的 ID):
将其添加到您的网格代码中:
控制器代码:
将类别传回,并过滤将结果放入网格之前。
I ran into the same thing, so I just use jQuery to get the data for each page (Replace #category with the ID of your category dropdown):
Add this to your Grid code:
Controller code:
Pass the category back, and filter the results before putting it into the grid.
来自文档。
Telerik Grid for ASP.NET MVC 使用其内置的基于 Linq 的表达式引擎来执行网格操作 - 分页、排序和过滤。然而在某些情况下,开发人员可能希望绕过表达式引擎和页面,自己对网格数据进行排序或过滤。这称为“自定义绑定”。
链接如下:
http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-data-binding-custom-binding.html
根据例子;如果这是您加载页面的控制器:
那么您的回发将是您可以过滤此内容的地方:
From the docs.
Telerik Grid for ASP.NET MVC is using its built-in Linq-based expression engine to perform the grid operations - paging, sorting and filtering. However in some cases the developer may want to bypass the expression engine and page, sort or filter the grid data by himself. This is called "Custom binding".
Heres the link:
http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-data-binding-custom-binding.html
as per the example; if this was your controller that loaded your page:
Then your post back would be a place you could filter this:
我可以在没有任何代码的情况下给出一些指示(我的 MVC 有点生疏,而且我没有时间编写示例代码)。
所以基本上你有一个页面是下拉列表,然后是另一个页面是网格。
您需要的是:
HTH
I can give a few directions without any code (my MVC is a bit rusty and I lack time to code samples).
So basically you have one page where the dropdown is and then another page where the grid will be.
What you need is:
HTH