修改 Telerik MVC ComboBox 中的默认过滤器字段
Modify the default Filter Field in a Telerik MVC ComboBox
过滤 Telerik MVC ComboBox 时,控件默认从 DataTextField 中的值进行过滤。我的 ComboBox 绑定到具有多个字段的数据,我使用这些字段在带有自定义模板的 table 中显示。我知道没有现成的解决方案可以过滤多个字段,但我想知道是否有办法 运行 在我组合了多个值的字段上进行过滤。
这是我的组合框:
@(Html.Kendo().ComboBoxFor(m => m.InputData.PublicationId)
.DataTextField("ID")
.DataValueField("ID")
.BindTo(Model.Publications)
.Filter(FilterType.Contains)
.TemplateId("pubListItemTemplate")
.HeaderTemplateId("pubListHeaderTemplate")
)
我的数据结构如下:
{ ID: "AJ", Description: "American Journal", Combined: "AJ American Journal" }, etc...]
这里的问题是,如果用户输入 "AJ",过滤器会找到上面的示例,但如果他们输入 "American",则不会;因为指定的 DataTextField 正在过滤 ID。
我需要它在名为 "Combined" 的字段上进行过滤,但我仍然需要使用 "ID" 作为 DataTextField,以便 ID 仅在它们之后显示在组合中'选择了项目。
这是在 Telerik 论坛上提供给我的,我已经确认它解决了我的问题:
@(Html.Kendo().ComboBoxFor(m => m.InputData.PublicationId)
.DataTextField("ID")
.DataValueField("ID")
.Events(events => events.Filter("onPubFilter"))
.BindTo(Model.Publications)
.Filter(FilterType.Contains)
.TemplateId("pubListItemTemplate")
.HeaderTemplateId("pubListHeaderTemplate")
)
<script>
function onPubFilter(ev) {
var filterValue = ev.filter.value;
ev.preventDefault();
this.dataSource.filter({
filters: [
{
field: "Combined",
operator: "contains",
value: filterValue
}
]
});
}
</script>
过滤 Telerik MVC ComboBox 时,控件默认从 DataTextField 中的值进行过滤。我的 ComboBox 绑定到具有多个字段的数据,我使用这些字段在带有自定义模板的 table 中显示。我知道没有现成的解决方案可以过滤多个字段,但我想知道是否有办法 运行 在我组合了多个值的字段上进行过滤。
这是我的组合框:
@(Html.Kendo().ComboBoxFor(m => m.InputData.PublicationId)
.DataTextField("ID")
.DataValueField("ID")
.BindTo(Model.Publications)
.Filter(FilterType.Contains)
.TemplateId("pubListItemTemplate")
.HeaderTemplateId("pubListHeaderTemplate")
)
我的数据结构如下:
{ ID: "AJ", Description: "American Journal", Combined: "AJ American Journal" }, etc...]
这里的问题是,如果用户输入 "AJ",过滤器会找到上面的示例,但如果他们输入 "American",则不会;因为指定的 DataTextField 正在过滤 ID。
我需要它在名为 "Combined" 的字段上进行过滤,但我仍然需要使用 "ID" 作为 DataTextField,以便 ID 仅在它们之后显示在组合中'选择了项目。
这是在 Telerik 论坛上提供给我的,我已经确认它解决了我的问题:
@(Html.Kendo().ComboBoxFor(m => m.InputData.PublicationId)
.DataTextField("ID")
.DataValueField("ID")
.Events(events => events.Filter("onPubFilter"))
.BindTo(Model.Publications)
.Filter(FilterType.Contains)
.TemplateId("pubListItemTemplate")
.HeaderTemplateId("pubListHeaderTemplate")
)
<script>
function onPubFilter(ev) {
var filterValue = ev.filter.value;
ev.preventDefault();
this.dataSource.filter({
filters: [
{
field: "Combined",
operator: "contains",
value: filterValue
}
]
});
}
</script>