使用 Razor 在 Telerik MVC3 网格中选择筛选器选项
我正在使用 Telerik MVC3 扩展,特别是 Grid,可以在 此处
我正在使用自定义分页,并对过滤选项感兴趣。
允许使用以下内容过滤每列是很容易的:
.Columns(x =>
{
x.Bound(col => col.Id).Filterable(false);
但是,当我启用它时,似乎我无法选择向用户呈现哪些选项。无论字段如何,我都会在过滤器下拉列表中得到以下内容:
理想情况下,我只想要“包含”-这可能吗?
I am playing about with the Telerik MVC3 extensions and in particular the Grid, which can be seen here
I am using custom paging and interested in the options around filtering.
It is easy enough to allow filtering per column with the following:
.Columns(x =>
{
x.Bound(col => col.Id).Filterable(false);
However it seems as though I have no choice over which options are presented to the user when I do enable it. No matter the field, I get the following in the filter dropdown:
Ideally I'd only want 'Contains' - is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我的解决方案是这样的:
Telerik GRID代码:
JavaScript代码:
结果看起来像:
My solution is like this:
Telerik GRID code:
JavaScript code:
Result looks like:
Stef 提供的答案是在我们的应用程序中实现的答案,但我注意到它不适用于多列可过滤的情况。我对 JS 做了一个小改动,以允许使用 Stef 的解决方案进行多列过滤。本质上,它的代码是相同的(所以所有的票都投给 Stef)。它只是进一步按“t-animation-container”进行分组(因为这是过滤器渲染到的元素),并像 Stef 的代码对页面所做的那样单独对每个元素进行操作。
就在提出这个解决方案后,我发现了另一个问题。它不再以连接到“FilterOnlyOn_Contains”过滤器的“t-animation-container”为目标。它会影响所有过滤器,因此会编辑我们不希望它编辑的元素。我不知道这种关系是如何建立的,我猜有 Telerik js 文件创建的 js dom 引用。
The answer provided by Stef is the one that was implemented in our application, but I noticed it didn't work for cases where multiple columns were filterable. I have made a small change to the JS to allow multiple column filtering with Stef's solution. Essentially, its the same code (so all upvotes to Stef). It simply takes a further step in grouping by "t-animation-container"s (as that is the element the filters are rendered to), and acting on each individually as Stef's code did to the page.
Just after coming up with this solution, I found another issue with it. It no longer targets "t-animation-container"s which are joined to the "FilterOnlyOn_Contains" filter. It affects all filters and hence edits elements we don't want it to. I don't know how this relationship is made, I guess there are js dom references that the telerik js file makes.
我不知道如何删除其他选项,但您可以通过将以下代码放入 grid_load 客户端事件中将“包含”选项设置为默认项目:
我认为您可以通过跟踪上述代码轻松删除其他项目在 FireBug 或 Chrome 开发者工具中。
I don't know how you can remove other options but you can set the "contains" option as a default item by putting the following code in your grid_load client-side event :
I think you can remove other items easily by tracing the above code in FireBug or Chrome Developer Tools.
如果可能的话,我怀疑您需要查看 telerik.grid.filtering.js javascript 文件并根据您的意愿进行编辑。
if it is possible I suspect you need to take a look in the telerik.grid.filtering.js javascript file and edit it to your wishes.