Kendo UI 具有可过滤多列的组合框
Kendo UI combobox with filterable multi columns
我一直在尝试实现它,但没有成功。这是我的场景:
我需要实现一个启用文本的 kendo 组合框,这样您可以输入一些文本,它会找到任何匹配的记录,但是,如果我单击下拉箭头,它会显示它里面的网格包含所有匹配的记录(部分搜索),它应该允许在列的 header.
中进行过滤
我看过 DropDownList 的示例,里面有一个网格,但您无法在文本框中键入文本。
有没有人有关于如何实现这个的示例?
提前感谢您的回复
罗恩
我终于让它工作了,如果有人想知道如何实现它,这里是演示
<html>
<head>
<script src="script/jquery.min.js" type="text/javascript"></script>
<script src="script/kendo.all.min.js" type="text/javascript"></script>
<script>
var rootElement;
var grid;
var comboBox;
$(document).ready(function () {
comboBox = $('#comboList').kendoComboBox({
dataTextField:"name",
dataValueField:"id",
filter:"contains",
open: function (e) {
if (!$(grid.element).hasClass("k-custom-visible")) {
$(grid.element).slideToggle("fast", function () {
comboBox.close();
var selectedValue = $('#comboList').closest("span").children("span").children("input").val(); // comboBox.value();
if (selectedValue.length > 0) {
var filter = new Array();
if (!isNaN(selectedValue)){
filter.push({ field: "id", operator: "contains", value: selectedValue });
} else {
filter.push({ field: "name", operator: "contains", value: selectedValue });
}
grid.dataSource.filter(filter);
} else {
grid.dataSource.filter([]);
}
$(grid.element).addClass("k-custom-visible");
});
}
},
change: function (e) {
if ($(grid.element).hasClass("k-custom-visible")) {
var selectedValue = $('#comboList').closest("span").children("span").children("input").val(); // comboBox.value();
if (selectedValue.length > 0) {
var filter = new Array();
if (!isNaN(selectedValue)) {
filter.push({ field: "id", operator: "contains", value: selectedValue });
} else {
filter.push({ field: "name", operator: "contains", value: selectedValue });
}
grid.dataSource.filter(filter);
} else {
grid.dataSource.filter([]);
}
$(grid.element).addClass("k-custom-visible");
}
},
dataSource: [
{ name: "Cotton", id: "1" },
{ name: "Polyester", id: "2" },
{ name: "Cotton/Polyester", id: "3" },
{ name: "Rib Knit", id: "4" }
]
}).data("kendoComboBox");
rootElement = $(comboBox.rootElement);
grid = $("#grid").kendoGrid({
dataSource: {
data:[
{ name: "Cotton", id: "1" },
{ name: "Polyester", id: "2" },
{ name: "Cotton/Polyester", id: "3" },
{ name: "Rib Knit", id: "4" }
]
},
columns: [
{
title: "User Id",
field: "id"
},
{
title: "User Name",
field: "name"
}
],
selectable: true,
pageable: true,
filterable: {
mode: "row"
},
change: function (e) {
var selected = $.map(this.select(), function(item){
return $(item)[0].cells[0].innerHTML;
});
comboBox.value(selected[0]);
$(grid.element).slideToggle('fast', function () {
$(grid.element).removeClass("k-custom-visible");
});
}
}).data("kendoGrid");
$(grid.element).css({ "border": "1px solid grey", "display": "none", "position": "absolute" });
$(grid.element).css({ "top": rootElement.position().top + rootElement.height(), "left": rootElement.position().left });
});
$(document).click(function (e) {`enter code here`
// Ignore clicks on the grid.
if (!$(e.target).hasClass("k-button") && !$(e.target).hasClass("k-textbox")) {
if ($(e.target).closest("div.k-grid").length == 0 && $(e.target).closest(".k-grid-edit").length == 0 && $(e.target).closest(".k-grid-edit-row").length == 0) {
// If visible, then close the grid.
if ($(grid.element).hasClass("k-custom-visible")) {
$(grid.element).slideToggle('fast', function () {
$(grid.element).removeClass("k-custom-visible");
});
}
}
}
});
</script>
</head>
<body>
<div>
<input id="comboList" placeholder="Enter Name" />
<div id="grid" style="width:800px; z-index:10;"></div>
</div>
</body>
</html>
我一直在尝试实现它,但没有成功。这是我的场景:
我需要实现一个启用文本的 kendo 组合框,这样您可以输入一些文本,它会找到任何匹配的记录,但是,如果我单击下拉箭头,它会显示它里面的网格包含所有匹配的记录(部分搜索),它应该允许在列的 header.
中进行过滤我看过 DropDownList 的示例,里面有一个网格,但您无法在文本框中键入文本。
有没有人有关于如何实现这个的示例?
提前感谢您的回复
罗恩
我终于让它工作了,如果有人想知道如何实现它,这里是演示
<html>
<head>
<script src="script/jquery.min.js" type="text/javascript"></script>
<script src="script/kendo.all.min.js" type="text/javascript"></script>
<script>
var rootElement;
var grid;
var comboBox;
$(document).ready(function () {
comboBox = $('#comboList').kendoComboBox({
dataTextField:"name",
dataValueField:"id",
filter:"contains",
open: function (e) {
if (!$(grid.element).hasClass("k-custom-visible")) {
$(grid.element).slideToggle("fast", function () {
comboBox.close();
var selectedValue = $('#comboList').closest("span").children("span").children("input").val(); // comboBox.value();
if (selectedValue.length > 0) {
var filter = new Array();
if (!isNaN(selectedValue)){
filter.push({ field: "id", operator: "contains", value: selectedValue });
} else {
filter.push({ field: "name", operator: "contains", value: selectedValue });
}
grid.dataSource.filter(filter);
} else {
grid.dataSource.filter([]);
}
$(grid.element).addClass("k-custom-visible");
});
}
},
change: function (e) {
if ($(grid.element).hasClass("k-custom-visible")) {
var selectedValue = $('#comboList').closest("span").children("span").children("input").val(); // comboBox.value();
if (selectedValue.length > 0) {
var filter = new Array();
if (!isNaN(selectedValue)) {
filter.push({ field: "id", operator: "contains", value: selectedValue });
} else {
filter.push({ field: "name", operator: "contains", value: selectedValue });
}
grid.dataSource.filter(filter);
} else {
grid.dataSource.filter([]);
}
$(grid.element).addClass("k-custom-visible");
}
},
dataSource: [
{ name: "Cotton", id: "1" },
{ name: "Polyester", id: "2" },
{ name: "Cotton/Polyester", id: "3" },
{ name: "Rib Knit", id: "4" }
]
}).data("kendoComboBox");
rootElement = $(comboBox.rootElement);
grid = $("#grid").kendoGrid({
dataSource: {
data:[
{ name: "Cotton", id: "1" },
{ name: "Polyester", id: "2" },
{ name: "Cotton/Polyester", id: "3" },
{ name: "Rib Knit", id: "4" }
]
},
columns: [
{
title: "User Id",
field: "id"
},
{
title: "User Name",
field: "name"
}
],
selectable: true,
pageable: true,
filterable: {
mode: "row"
},
change: function (e) {
var selected = $.map(this.select(), function(item){
return $(item)[0].cells[0].innerHTML;
});
comboBox.value(selected[0]);
$(grid.element).slideToggle('fast', function () {
$(grid.element).removeClass("k-custom-visible");
});
}
}).data("kendoGrid");
$(grid.element).css({ "border": "1px solid grey", "display": "none", "position": "absolute" });
$(grid.element).css({ "top": rootElement.position().top + rootElement.height(), "left": rootElement.position().left });
});
$(document).click(function (e) {`enter code here`
// Ignore clicks on the grid.
if (!$(e.target).hasClass("k-button") && !$(e.target).hasClass("k-textbox")) {
if ($(e.target).closest("div.k-grid").length == 0 && $(e.target).closest(".k-grid-edit").length == 0 && $(e.target).closest(".k-grid-edit-row").length == 0) {
// If visible, then close the grid.
if ($(grid.element).hasClass("k-custom-visible")) {
$(grid.element).slideToggle('fast', function () {
$(grid.element).removeClass("k-custom-visible");
});
}
}
}
});
</script>
</head>
<body>
<div>
<input id="comboList" placeholder="Enter Name" />
<div id="grid" style="width:800px; z-index:10;"></div>
</div>
</body>
</html>