I have a Kendo UI grid that is rendered with javaScript. I want the string columns to have a single option ("Contains") and without the second filter. So far so good, I wrote
$("#MyGrid").kendoGrid({
// other bits of configuration here
filterable: {
extra:false,
operators: {
string:{ contains: "Contains"}
}
},
// more bits of configuration here
});
As part of the definition of the grid. And the result looks good-ish (I only have one option, so the drop down is redundant).
However, regardless of this, the filter still performs the equals operation rather than the contains operation (which is the only one available to it).
I've spent a while trying to figure this out and I keep going around in circles because the code I found either does not work, or doesn't make sense, or both.
Can anyone tell me how to default the filter to "Contains" and not "Is Equal To"?
I had the same problem and I got it, that it needs the .Clear() option!
I am building my Grid with the MVC Wrapper in Razor:
@(Html.Kendo().Grid<LocationViewModel>()
.Name("locationGrid")
// other bits of configuration here
.ColumnMenu()
.Filterable(f => f.Operators(o => o.ForString(s => s
.Clear()
.Contains("Contains")
.DoesNotContain("Does not contain")
.EndsWith("Ends with")
)))
// other bits of configuration here
)
Summary:
.Contains()
first after .Clear()
then the default is Contains!Additional Info: I am using Kendo UI 2013.1.514
Try to update to latest internal build. Version later than 2012.3.1304 should contain the fix.
The best way to change the default operator for all of the instances:
kendo.ui.FilterMenu.prototype.options.operators =
$.extend(kendo.ui.FilterMenu.prototype.options.operators, {
string: {
contains: "Contains",
startswith: "Starts with",
eq: "Is equal to",
neq: "Is not equal to",
doesnotcontain: "Does not contain",
endswith: "Ends with"
}
});
and the complete script:
kendo.ui.FilterMenu.prototype.options.operators =
$.extend(kendo.ui.FilterMenu.prototype.options.operators, {
/* FILTER MENU OPERATORS (for each supported data type)
****************************************************************************/
string: {
contains: "Contains",
startswith: "Starts with",
eq: "Is equal to",
neq: "Is not equal to",
doesnotcontain: "Does not contain",
endswith: "Ends with"
},
number: {
eq: "Is equal to",
neq: "Is not equal to",
gte: "Is greater than or equal to",
gt: "Is greater than",
lte: "Is less than or equal to",
lt: "Is less than"
},
date: {
eq: "Is equal to",
neq: "Is not equal to",
gte: "Is after or equal to",
gt: "Is after",
lte: "Is before or equal to",
lt: "Is before"
},
enums: {
eq: "Is equal to",
neq: "Is not equal to"
}
/***************************************************************************/
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With