当前位置 : 主页 > 网络编程 > ASP >

asp.net-mvc-3 – 使用Razor在Telerik MVC3网格中选择过滤器选项

来源:互联网 收集:自由互联 发布时间:2021-06-24
我正在玩Telerik MVC3扩展,特别是网格,可以看到 here 我正在使用自定义分页,并对围绕过滤的选项感兴趣. 使用以下内容很容易允许每列过滤: .Columns(x ={ x.Bound(col = col.Id).Filterable(false); 但是
我正在玩Telerik MVC3扩展,特别是网格,可以看到 here

我正在使用自定义分页,并对围绕过滤的选项感兴趣.

使用以下内容很容易允许每列过滤:

.Columns(x =>
{
    x.Bound(col => col.Id).Filterable(false);

但是,当我启用它时,似乎我无法选择向用户显示哪些选项.无论在哪个领域,我都会在过滤器下拉列表中获得以下内容:

理想情况下,我只想要’包含’ – 这可能吗?

我的解决方案是这样的:

Telerik GRID代码:

columns.Bound(o => o.MRUCode).HeaderHtmlAttributes(new { @class = "FilterOnlyOn_Contains" });

JavaScript代码:

$(".FilterOnlyOn_Contains .t-filter").click(function () {
    setTimeout(function () {
        // Remove all existing options and add 'Contains'
        var filterOptions1 = $(".t-filter-operator").first();
        filterOptions1.empty();
        filterOptions1.append($("<option />").val("substringof").text("Contains"));

        // Remove second part (options + text + input)
        var filterOptions2 = $(".t-filter-operator").last();
        filterOptions2.hide();
        $(".t-filter-help-text").text("");
        $("input[type=text]").last().hide();
    });
});

结果如下:

网友评论