Reputation: 1160
Because I'm using a lot of kendo grids spread in the whole web app, I start to introduce some redundant code that causes me a lot of troubles. Imagine to have something like:
//MVC:
...
columns.Bound(c => c.Column1).Filterable(f => f.Extra(false)
.Operators(o => o.ForString(str => str.Clear().Contains("Contains")))
.Cell(c => .ShowOperators(false).Template("column1Filter")))
.Title("Column One");
...
//JS:
function column1Filter(container) {
container.element.kendoAutoComplete({
filter: "contains",
dataTextField: "Column1",
dataValueField: "Column1",
valuePrimitive: true,
dataSource: container.dataSource
});
}
Then, having this method reproduced for each single columns in each single grids. Is there any way where I can I have only one method that creates the kendo autocomplete? E.G:
function genericAutocompleteFilter(container) {
var columnsName = //...Meh!
container.element.kendoAutoComplete({
filter: "contains",
dataTextField: columnsName,
dataValueField: columnsName,
valuePrimitive: true,
dataSource: container.dataSource
});
}
Upvotes: 0
Views: 886
Reputation: 1160
At the end, there are two ways to do it. For the column "color", we can use it with kendo MVC (razor). While the column "size", it's from @massimo-franciosa 's suggestion.
http://dojo.telerik.com/uqita/5.
Upvotes: 0
Reputation: 564
I think you can use a closure to get the function you need customized for you columnName. something like:
function getAutoCompleteFunction(columnName) {
return function (container) {
container.element.kendoAutoComplete({
filter: "contains",
autoBind: false,
dataTextField: columnName,
dataValueField: columnName,
valuePrimitive: true,
dataSource: container.dataSource
})
}
and then use getAutoCompleteFunction("column1") for example.
Upvotes: 1