Reputation: 2745
I try to remove an item from dropdown of Kendo grid filter. But it is still rendered. How can I reach such behaviour?
$("#grid").kendoGrid({
columns: [
{ field: "someDate", type: "date" }
],
dataSource: [
{ someDate: "2016-3-29"},
{ someDate: "2016-3-30"}
],
filterable: {
extra: true,
operators: {
date: {
gte: "Is after or equal to",
lte: "Is before or equal to"
}
}
},
filterMenuInit: function(e) {
e.container.find("select:eq(0)>option")[1].remove();
e.container.find("select:eq(1)>option")[1].remove();
e.container.find("select:eq(2)>option")[0].remove();
}
});
Link on dojo. Please help.
EDITED: I need two complex filters for dates. In the first filter I need only "Is after or equal to", then "AND", and in the second filter I need only "Is before or equal to". I try to do this by removing "Is before or equal to" from the first dropdown and "Is after or equal to" from the second one.
Upvotes: 1
Views: 5786
Reputation: 61
see the below example use filterable: false in field section to remove filter from column.
<div id="grid"></div>
<script>
$("#grid").kendoGrid({
columns: [
{ field: "name", filterable: false },
{ field: "age" }
],
filterable: true,
dataSource: [ { name: "Jane", age: 30 }, { name: "John", age: 33 }]
});
</script>
Upvotes: -1
Reputation: 817
You need to get the kendoDropDownList object, then remove the item from the dataSource; I have updated your dojo
<script>
$("#grid").kendoGrid({
columns: [
{ field: "name" }
],
dataSource: [
{ name: "Jane Doe"},
{ name: "John Doe"}
],
filterable: true,
filterMenuInit: function(e) {
if (e.field == "name") {
var filter1 = e.container.find("select:eq(0)").data("kendoDropDownList");
var filter2 = e.container.find("select:eq(2)").data("kendoDropDownList");
filter1.dataSource.remove(filter1.dataSource.at(0));
filter1.select(0);
filter2.dataSource.remove(filter2.dataSource.at(0));
filter2.select(0);
}
}
});
</script>
Upvotes: 1
Reputation: 461
Instead of removing you can add only what you want
filterable: {
extra: false,
operators: {
string: {
startswith: "Starts with",
eq: "Is equal to",
neq: "Is not equal to"
}
}
},
Upvotes: 3