Asp.net mvc 使用DropdownlistFor搜索/过滤KendoUI网格中的所有列
我正在尝试使用我的自定义下拉列表过滤/搜索kendoUI网格。我已经能够得到单栏过滤的结果,但是如果我尝试添加新的dropdownlist来过滤网格,我就无法得到所需的结果。 我的问题是逻辑运算符,它的值不同。 这是正确的方法吗?还有其他建议吗 我在这里添加更多的描述图像,希望你能帮助我。谢谢 HTML下拉列表:Asp.net mvc 使用DropdownlistFor搜索/过滤KendoUI网格中的所有列,asp.net-mvc,kendo-ui,Asp.net Mvc,Kendo Ui,我正在尝试使用我的自定义下拉列表过滤/搜索kendoUI网格。我已经能够得到单栏过滤的结果,但是如果我尝试添加新的dropdownlist来过滤网格,我就无法得到所需的结果。 我的问题是逻辑运算符,它的值不同。 这是正确的方法吗?还有其他建议吗 我在这里添加更多的描述图像,希望你能帮助我。谢谢 HTML下拉列表: <html> <div class="form-group col-md-2" style="margin-bottom:0px;">
<html>
<div class="form-group col-md-2" style="margin-bottom:0px;">
@Html.Label("Media", htmlAttributes: (new { @class = "col-sm-4 control-label" }))
<div class="col-sm-8" style="float:none;">
@Html.DropDownListFor(model => model.MediaTypeID, (ViewData["media"] as SelectList), "select media", new { @class = "form-control btnregister chosen-select", onchange = "changes_dropdown(this.id)", data_placeholder = "select media", style = "border-bottom:none;border-radius:0px;" })
@* @Html.ValidationMessageFor(model => model.MediaTypeID, "", new { @class = "text-danger" })*@
</div>
</div>
<div class="form-group col-md-2" style="margin-bottom:0px;">
@Html.Label("Outlet", htmlAttributes: (new { @class = "col-sm-4 control-label" }))
<div class="col-sm-8" style="float:none;">
@Html.DropDownListFor(model => model.channel, (ViewData["company"] as SelectList), "select channel", new { @class = "form-control btnregister chosen-select", onchange = "changes_dropdown(this.id)", data_placeholder = "select channel", style = "border-bottom:none;border-radius:0px;" })
@Html.ValidationMessageFor(model => model.channel, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group col-md-2" style="margin-bottom:0px;">
@Html.Label("Start Date", htmlAttributes: (new { @class = "col-sm-6 control-label" }))
<div class="col-sm-6" style="float:none;">
@Html.DropDownListFor(model => model.EntryDate, (ViewData["entryDate"] as SelectList), "select date", new { @class = "form-control btnregister chosen-select", onchange = "changes_dropdown(this.id)", data_placeholder = "select date", style = "border-bottom:none;border-radius:0px;", id = "startDate" })
@Html.ValidationMessageFor(model => model.EntryDate, "", new { @class = "text-danger" })
</div>
</div>
</html>
@Label(“媒体”,htmlAttributes:(新的{@class=“col-sm-4控制标签“}))
@Html.DropDownListFor(model=>model.MediaTypeID,(ViewData[“media”]作为SelectList),“select media”,new{@class=“form control btnregister select select”,onchange=“changes\u dropdown(this.id)”,data\u placeholder=“select media”,style=“border bottom:none;border radius:0px;”)
@*@Html.ValidationMessageFor(model=>model.MediaTypeID,“,new{@class=“text danger”})*@
@Label(“Outlet”,htmlAttributes:(新的{@class=“col-sm-4控制标签“}))
@Html.DropDownListFor(model=>model.channel,(查看数据[“公司”]作为选择列表),“选择频道”,新建{@class=“form control btnregister Selected select”,onchange=“changes\u dropdown(this.id)”,data\u placeholder=“select channel”,style=“border bottom:无;border radius:0px;”)
@Html.ValidationMessageFor(model=>model.channel,“,new{@class=“text danger”})
@Label(“开始日期”,htmlAttributes:(新的{@class=“col-sm-6控制标签“}))
@Html.DropDownListFor(model=>model.EntryDate,(ViewData[“EntryDate”]作为SelectList),“select date”,new{@class=“form control btnregister select”,onchange=“changes\u dropdown(this.id)”,data\u placeholder=“select date”,style=“border bottom:none;border radius:0px;”,id=“startDate”})
@Html.ValidationMessageFor(model=>model.EntryDate,“,new{@class=“text danger”})
Javascript函数和填充:
<script type="text/javascript">
function changes_dropdown(fieldID)
{
var fieldValue = document.getElementById(fieldID).value;
$("#grid").data("kendoGrid").dataSource.filter({
logic: "and",
filters: [
{
field: fieldID,
operator: "contains",
value: fieldValue
}
]
});
}
</script>
功能更改\u下拉列表(字段ID)
{
var fieldValue=document.getElementById(fieldID).value;
$(“#网格”).data(“kendoGrid”).dataSource.filter({
逻辑:“和”,
过滤器:[
{
字段:fieldID,
操作员:“包含”,
值:字段值
}
]
});
}
首先,您不需要将当前字段的id传递给更改\u下拉列表
功能。相反,您可以使用onchange=“changes\u dropdown()
并在此函数中使用var fieldValue=this.value
此外,定义单个筛选器时,不需要指定谓词()之间的逻辑:
谢谢你的回答,这对我很有帮助
$("#grid").data("kendoGrid").dataSource.filter({
filters: [
{
field: fieldID,
operator: "contains",
value: fieldValue
}
]
});