Morning,
I've been using the Kendo Grid for years and absolutely love it for what I can do with it, but every so often I get asked to stretch the functionality of what it can do, I haven't found much documentation on this, but i'll try my best to give an example of what I've done, and to see if there is a better way of doing it..
I have a field in my Grid that is a string, with multiple "Tags" explicitly given in the dataSource in filterable.
{
"columnMenu": {
"componentType": "modern"
},
"stickable": true,
"field": "conditions",
"filterable": {
"enabled": true,
"multi": true,
"search": true,
"dataSource": [
{
"conditions": "TEST123"
},
{
"conditions": "TEST"
},
{
"conditions": "ABC"
},
{
"conditions": "DEF"
}
]
},
"groupable": true,
"aggregates": "count",
"groupHeaderTemplate": "Conditions: #= value # (Count: #= count#)",
"sortable": true,
"title": "Conditions",
The data in the field is a string of comma separated tags, i.e.
TEST, ABC, DEF
I've updated the filter method on the Grid so that I can select multiple options in the filter menu, and it does a "contains" look up to match multiple hits.
filter: function(e){
this.columns.forEach(function(f){
if(e.field === f.field){
if(f.filterable.hasOwnProperty('dataSource')){
e.filter.filters.forEach(function(f){
f.operator = "contains";
e.filter.logic = "and";
})
}
}
})
},
I have two issues here.
1. I'm using contains, so if the tags are similar (TEST, TEST123), selecting TEST will show both TEST and TEST123 - which isn't ideal.
2. If I select an option from the filter menu, it doesn't remain checked if you were to go back into the filter menu again.
I've asked this question before and had some great help to get it to this point using: https://docs.telerik.com/kendo-ui/knowledge-base/grid-how-to-change-multi-checkbox-filter-to-contains but I'm wondering if there is a better way of achieving the functionality I'm looking for here with the grid. I added square brackets to the tags to distinguish them ([TEST], [TEST123]) , but my users didn't like this change.
Is there a way to do this without using contains?
I'd also like to be able to see the selected option in the filter menu - I can find the checkbox through jQuery, but I cannot toggle it's state..
e.filter.filters.forEach(function(f){
var checkbox = $(".k-filter-menu").find("input[value='"+f.value+"']");
console.log(checkbox);
checkbox.prop("checked", true).trigger("change");
checkbox.attr("checked", true).trigger("change");
f.operator = "contains";
e.filter.logic = "and";
})
Thanks for your help,
Matt