Reputation: 1298
I am using a KendoUI grid, I want to add checkbox filters to my grid. The problem I have is that I want the to filter to display a particular field from my datasource but actually filter on an id field.
My code is:
var ds = [{country: "BG", id: 1},{country: "GRM", id: 2}, {country: "USA", id: 3}];
$("#grid").kendoGrid({
columns: [ {
field: "id",
template: "${ SetDisplayText(id)}",
filterable: {
multi:true,
dataSource: ds
}
} ],
filterable: true,
dataSource: ds
});
function SetDisplayText(matchId) {
var matchSite = $.grep(ds, function(item) {
return item.id === matchId;
});
if (matchSite.length > 0) {
return matchSite[0].country;
} else {
return "";
}
}
As you can see I want display the name of the country in the filter but actually use it's id as the filter field.
Please see: http://dojo.telerik.com/ihECE/2
Upvotes: 1
Views: 2269
Reputation: 1298
The best solution I could come up with was to use a Template in the Filter. E.g.
multi: true,
dataSource: ds,
itemTemplate: function (e) {
return "<span><label><span class='multiFilter'>#= data.DisplayField || data.all #</span><input type='checkbox' name='" +e.field + "' value='#= data.ValueField == 0 ? null : data.ValueField #'/></label></span>";
}
Hope this helps somebody else.
Upvotes: 2
Reputation: 2748
I think you may be attacking the problem wrong, but I'm not sure if you're just oversimplifying the question for your real problem.
If the ids are unique for each country, then just include the country on your grid instead of the id. If you need the ids after the user has filtered the dataset, then you can access them using something like this. Its even easier if serverPaging is false.
Upvotes: 0