This is a migrated thread and some comments may be shown as answers.

kendoFilterMultiCheck - trigger refresh when datasource is modified

7 Answers 1104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 11 Dec 2020, 12:30 PM

I would really like to know how one can go about causing the multi select filter items in the kendoFilterMultiCheck dropdown list to refresh when the list is opened up after the datasource has been read again. I've had a look at the suggestions here:

https://www.telerik.com/forums/refresh-multi-checkbox-filter-options-when-grid-is-filtered

However, I don't want to use the serDataSource method because that triggers a re-rendering of the grid.

I don't want to create data sources for each colum that needs to be filtered as this is going to be too heavy on processing.

I don't want to use a data source and assign it to both the grid and the filterable data source as it alters the list of items in the dropdown when filtering is applied

There's a behavior that I was hoping to mimic programatically and that is the following:

The dropdown list is rendered correctly the first time it is clicked based on the state of the underlying grid's data source. If you've rendered the grid 5 times changing the datasource each time and then only click on the filter menu item, the list shows the latest data source's valid values.

If I re-read the datasource, how can I set the state of the filter item so that it is seen as the first time it is opened again?

I would really appreciate some help with this.

 

 

 

 

 

 

7 Answers, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 15 Dec 2020, 08:50 AM

Hi Matthew,

Thank you for the provided details on the scenario you are willing to achieve. Indeed, the options outlined in the referred are the recommended ones. This is due to the fact that the "checkSource" is built only once - when the grid is created. The setDataSource method of the grid rerenders it, causing the "checkSource" to be created once again with the currently available data set.

 

Best regards,
Tsvetomir
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Matthew
Top achievements
Rank 1
answered on 21 Dec 2020, 09:07 AM

Hi Tsvetomir, thank you very much for the response. Is it definitely when the grid is created? I've found that the data that is within the grid at the time the column header is clicked on is used to generate the list of items. So if you update the datasource again via the read method after the grid is created, the items at that point in time are used. So it seems to be when the grid header is clicked for the first time and not when the grid is rendered. But after that, subsequent calls to the read method have no influence on the filter items. Is there anyway I can replicate that method within the code? I've tried to remove the checkSource via js code but that just clears the list and then there are no items available in the filter. I'm really hoping to be able to repopulate that list as efficiently as it is when its created that first time but if that's not possible that's fine, I'm just hoping that there might be a way I can replicate that behavior programatically. Thanks very much.

 

 

 

 

1
Matthew
Top achievements
Rank 1
answered on 21 Dec 2020, 01:16 PM

Hi Tsvetomir, I'm not sure if this approach is a bit primitive but I found the code in the kendo.all.min.js file that is responsible for creating the initial list of filter values. It's in the _init event of the "kendoFilterMultiCheck" object it seems. What I've done is call that even again when the dataBound event of the grid fires. This is a sample of what I'm doing:

 

var arr = $('.k-filterable');
if (arr != null) {
    for (i = 0; i < arr.length; i++) {
        var fmc = $($('.k-filterable')[i]).data("kendoFilterMultiCheck");
         
        if (fmc != null) {
            fmc._init();
        }
    }
}

 

This works and achieves what I need it to do. Does this look like a suitable approach to you according to what I'm trying to achieve and considering what approaches I'm trying to avoid.

 

 

 

Thanks very much.

0
Accepted
Tsvetomir
Telerik team
answered on 22 Dec 2020, 01:09 PM

Hi Matt,

It is correct that the values for the menu are built within the "init" of the FilterMultiCheck object. And explicitly calling it, you would achieve the desired functionality.

However, what I can recommend is that you actually do extensive testing on the scenario. This is due to the fact that the init() method triggers other methods and doing this every time the DataBound event is triggered, you might experience a negative impact on the performance of your application.

Note that such modifications are not officially supported. However, after testing it out, you might stick to this code snippet with no issues.

 

Best regards,
Tsvetomir
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Matthew
Top achievements
Rank 1
answered on 23 Dec 2020, 06:52 AM

Hi Tsvetomir,

Thanks so much for the response. We've put the change into testing and I've also done what I can to try find any problems with the solution but so far it seems fine.

Thanks again for your assistance, much appreciated!!

Kind regards,

Matthew

 

 

0
Tsvetomir
Telerik team
answered on 23 Dec 2020, 04:00 PM

Hi Matthew,

I am glad to hear that the implementation has passed the tests on your side. If there is anything else that I can help with, do not hesitate to contact me back.

 

Kind regards,
Tsvetomir
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Dmitry
Top achievements
Rank 1
Iron
answered on 09 Aug 2021, 02:47 PM

Thanks to Matthew for posting this solution. I think Telerik needs to supply same tested functionality to reset multi-filters so their datasources will be recreate when needed.

I tried other options found of this forum and SO, but they didn't work well:
1.  `setDataSource()` call creates a weird bug in our setup only on chrome but not in edge where header row won't horizontally scroll with grid body.

2. Calling `fmc.checksource.read(); fmc.refresh()` causes main data source to be read again and extra query to server for full data is performed

3. Using same datasource as grid datasource produces duplicate values.

4. Creating custom datasource for each column with manually removing duplicate values required too much unnecessary dumb work.

While all is needed is small method on a grid to reset all/selected multi filters to initial state when they work perfectly. Calling internal undocumented `_init()` method for this looks weird and will lead to errors in future versions.

Georgi Denchev
Telerik team
commented on 11 Aug 2021, 11:59 AM

Hi, Dmitry,

You can create a single dataSource, which uses the data from the Grid and apply it to all of the columns. There is no need to create a separate one for each field.

After that you can use the columnMenuInit event and update the filterSource any time the menu is opened. The changes made to the the Grid's data will be reflected in the filter menus.

Example:

https://dojo.telerik.com/@gdenchev/iTAVUmaN 

Dmitry
Top achievements
Rank 1
Iron
commented on 13 Aug 2021, 03:31 PM

Thank you Georgi!
Your solution works fine. But still I'd like Telerik to think about adding feature to allow reset filters on grid datasource read. With your solution I see one drawback - filter options are calculated each time user opens menu even if data is not changed. I know caching could be added, but it's again a bit of extra code. Default multi filters works fine - initialized when first accessed, cache values, removes duplicates. We just need ability to reset their state on data change so they are reread when needed. Something like that solution with `_init()` call, but "official".
Georgi Denchev
Telerik team
commented on 17 Aug 2021, 11:11 AM

Hi, Dmitry,

What I could recommend at this moment, is for you to open a Feature Request in our Feedback Portal and provide the details about the requested functionality there. This way the Devs can see it and they'll determine whether it is plausible to implement or not.

Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
Matthew
Top achievements
Rank 1
Dmitry
Top achievements
Rank 1
Iron
Share this question
or