Sort & Filter field which is multivalue

0 Answers 102 Views
Grid
Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
Aleksandr asked on 28 Dec 2022, 12:39 AM

we have a field in which the source value is an array of objects, to edit it we use kendoMultiSelect, to show we just concat the values:

 


this.MultiSelectEmployeeClassesArrayToString = function (item) {
            return item.EmployeeLicensingClasses
                .map(function (employeeClass) { return employeeClass.Description; })
                .join(', ');
        },

is there a way to make filtering work as a contains for example & sort just the value we display (concatenating)?

 

Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
commented on 28 Dec 2022, 02:56 PM

in other words, can I override the filter function for a specific field?
Nikolay
Telerik team
commented on 30 Dec 2022, 11:27 AM

Hi Aleksandr, 

Generally speaking, the MultiSelect allows you to select values from a predefined list of choices. If the typed value does not exist in this list the user will not be able to use it as a value.

Here is an article on Filter Grid by Using the MultiSelect: https://docs.telerik.com/kendo-ui/knowledge-base/filter-grid-with-multi-select-widget

Also, below I am posting an article on how to Modify the Default Behavior of Filter Operators:

Hope this helps. 

Regards,

Nikolay

 

Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
commented on 24 Jan 2023, 02:10 AM

Hello Nikolay,

the example you have provided not exactly what i was looking for, now trying to change the filter on the fly during grid filter event, does not work, could help figure out why

 


filter: function (e) { 

                        debugger;

                        if (e.field === "EmployeeLicensingClasses" && e.filter) {                            

                            var ecFilters = { logic: 'or', filters: [] };

                            var val = null;
                            

                            e.filter.filters.forEach(function (f) {
                                if (f.field === "EmployeeLicensingClasses") {
                                    val = f.value;
                                }
                            });

                            e.filter.filters = e.filter.filters.filter(function (f) {
                                return f.field !== "EmployeeLicensingClasses";
                            });

                            if (val) {
                                ecFilters.filters.push({ field: 'EmployeeLicensingClassesFlat', operator: 'contains', value: val })
                            };                            

                            e.filter.filters.push(ecFilters)
                        }
                    },               

 

Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
commented on 24 Jan 2023, 02:30 AM | edited

seems, another (not changed) filters are applied to datasource
Nikolay
Telerik team
commented on 26 Jan 2023, 11:28 AM

Hi Aleksandr,

Updating the e.filter expression will not update the internal filter logic. You can cancel the filter event with preventDefault() and filter the Grid with your custom logic by using the filter() method.

filter: function (e) { 
              e.preventDefault()
              if (e.field === "ShipName" && e.filter) { 
                var ecFilters = { logic: 'or', filters: [] };
                var val = null;

                e.filter.filters.forEach(function (f) {
                  if (f.field === "ShipName") {
                    val = f.value;
                  }
                });
                
                console.log("val", val)

                e.filter.filters = e.filter.filters.filter(function (f) {
                  return f.field !== "ShipName";
                });

                if (val) {
                  ecFilters.filters.push({ field: 'ShipName', operator: 'contains', value: "Hanari Carnes" })
                };                            

                e.filter.filters.push(ecFilters)
                e.sender.dataSource.filter(ecFilters)
                
              }
            }

Regards,

Nikolay

 

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Aleksandr
Top achievements
Rank 1
Bronze
Bronze
Veteran
Share this question
or