我正在使用看起来像这样的KendoGrid:
@(Html.Kendo().Grid<KendoProject.Models.DTO.ShedDto>()
.Name("ShedGrid")
.EnableCustomBinding(true)
.Filterable(f => f.Mode(GridFilterMode.Menu).Extra(false))
.Columns(
columns => {
columns.Bound(c => c.Batch).Filterable(f =>f.UI("$.proxy (ShedGridFilter, {field: 'Batch'})"));
columns.Bound(c => c.Shed).Filterable(f =>f.UI("$.proxy (ShedGridFilter, {field: 'Shed'}))"));
})
.Scrollable(s => s.Height("350px"))
.Editable(editable => editable.Mode(GridEditMode.InCell).DisplayDeleteConfirmation(false))
.AutoBind(true)
.DataSource(datasource => datasource
.Ajax()
.Model(model =>
{
model.Id(i => i.ShedId);
model.Field(f => f.Batch).Editable(false);
model.Field(f => f.Shed).Editable(false);
})
.Read(read => read.Action(MVC.MilkFeedShed.ActionNames.MilkFeedShed_Read, MVC.MilkFeedShed.Name).Data("selectedDateGetter"))
.Update(update => update.Action(MVC.MilkFeedShed.ActionNames.MilkFeedShed_Update, MVC.MilkFeedShed.Name).Data("selectedDateGetter"))
.PageSize(100)
.Batch(true)
.Sort(s => s.Add("ChangeTime").Descending())
)
)
过滤器的JavaScript如下所示:
function MilkFeedGridFilter(element) {
var grid = "ShedGrid";
var fieldName = this.field;
var gridDataItems = $("#" + grid).data("kendoGrid").dataSource.data();
var listDataItems = [];
for (var i = 0; i < gridDataItems.length; i++) {
if (gridDataItems[i][fieldName] !== null && $.inArray(gridDataItems[i][fieldName], listDataItems) < 0) {
listDataItems.push(gridDataItems[i][fieldName]);
}
}
listDataItems.sort();
element.kendoDropDownList({
dataSource: {
data: listDataItems
}
})
}
此设置在每个KendoGrid过滤器列中创建DropDownList,但我不知道如何为它们命名,以便我以后可以使用其他函数找到它们,基本上我想将以下内容翻译成JavaScript :
@(Html.Kendo().DropDownList()
.Name("BatchDropDown");
//.DataSource(List in JavaScript)
)
答案 0 :(得分:0)
修正了它!为元素添加了一个id,代码如下:
function MilkFeedGridFilter(element) {
var grid = "ShedGrid";
var fieldName = this.field;
var gridDataItems = $("#" + grid).data("kendoGrid").dataSource.data();
var listDataItems = [];
for (var i = 0; i < gridDataItems.length; i++) {
if (gridDataItems[i][fieldName] !== null && $.inArray(gridDataItems[i][fieldName], listDataItems) < 0) {
listDataItems.push(gridDataItems[i][fieldName]);
}
}
listDataItems.sort();
element[0].id = "BatchDropDown";
element.kendoDropDownList({
dataSource: {
data: listDataItems
}
})
}
我用它来选择它:
var dropDown = $("#BatchDropDown").getKendoDropDownList();