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

Trigger FilterMenuInit event after a row is added

3 Answers 182 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stu
Top achievements
Rank 1
Stu asked on 26 Aug 2015, 03:20 PM

I'm building the list of values a column can be filtered by using the FilterMenuInit event and the initCheckboxFilter(e) javascript code and it's working great.

Now I add a new row to the grid using the toolbar Create method and AJAX.  The new row might contain a value for the column being filtered that wasn't there before.  I would like to be able to add that new value to the existing list in the filter for that column.  Can I somehow set the FilterMenuInit event to be triggered again?

Thanks,
Stu

3 Answers, 1 is accepted

Sort by
0
eo
Top achievements
Rank 1
answered on 26 Aug 2015, 08:21 PM

Hello Stu,

You can trigger the FilterMenuInit manually everytime a create request is executed by taking advantage of the onRequestEnd event. You can configure your MVC project to do so, like it was explained in this Telerik forum post. ​Furthermore, if you want this to happen only on create, you could limit it by using the type property like this:

1.function onRequestEnd(e) {
2.    if (e.type === "create") {
3.        //YOUR LOGIC HERE
4.    }
5.  };

Hope this helps!

0
Stu
Top achievements
Rank 1
answered on 27 Aug 2015, 02:18 PM

Hi eo.  Thanks very much for your reply.  I put in the event for RequestEnd and it is firing and I can examine the event argument and see the type (create, read, etc.) and the data for the row just added.

But I have no idea how to translate that into calling the FilterMenuInit function.  The arguments are totally different.  And to be honest, the JS code I got from this post (http://docs.telerik.com/kendo-ui/web/grid/how-to/checkbox-filter-menu) works, but I have no idea how (I'm a little new to JS and this code is pretty complex).  Can you either show me how I would take the event argument from RequestEnd and translate that into the argument passed into function initCheckboxFilter(e) from the article above.  Or the simpler thing would be to somehow tell the grid to clear the state such that the FilterMenuInit event would be called again for each column filter action.

Thank you.

0
Boyan Dimitrov
Telerik team
answered on 31 Aug 2015, 06:16 AM

Hello Stu,

 

Indeed the filterMenuInit event is fired when the grid filter menu is initialized, when it is opened for the first time.

 

I think that easier solution would be accessing the menu container and manipulate its child elements ( add, remove or modify) rather than triggering the filterMenuInit event each time when a new row is added. 

 

In the following forum thread you can find a sample solution how to access the filterMenu container using the th element of the column. 

 

Regards,
Boyan Dimitrov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Stu
Top achievements
Rank 1
Answers by
eo
Top achievements
Rank 1
Stu
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or