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

Filtering inside dataBound event goes into recursion

4 Answers 728 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luke
Top achievements
Rank 1
Luke asked on 11 Mar 2014, 09:44 AM
Hi,
I'm trying to filter data inside dataBound event function, but it creates recursive calls to itself.
Could you tell me if this is a bug or am I doing something wrong?

Example: http://trykendoui.telerik.com/onAj
This is Event example from grid demos with modification inside "function onDataBound(arg)".

function onDataBound(arg) {
                    kendoConsole.log("Grid data bound");
                      var l_Data = this.dataSource;
                    l_Data.filter( {
                        field: "UnitsInStock",
                        operator: "eq",
                        value: 39
                        } );
                }

4 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 11 Mar 2014, 02:57 PM
Hello Luke,


This is the expected behavior, because the dataBound event is fired each time the Grid is binding it's data, including when a filtering/sorting/grouping etc. is performed.

Let me know if I could assist you further on this topic.

Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Luke
Top achievements
Rank 1
answered on 12 Mar 2014, 08:48 AM
Hi Dimiter,

I corrected my function to:

01.GridOnDataBound: function(p_Event, p_This, p_Own, p_Parent)
02.{
03.    if( typeof(p_This.dataSource.IsFiltered)=='undefined'
04.        || p_This.dataSource.IsFiltered===false)
05.    {
06.        p_This.dataSource.IsFiltered = true;
07.        var l_Data = p_This.dataSource;
08.        l_Data.filter({
09.            field: p_Own,
10.            operator: "eq",
11.            value: parseInt(p_Parent)
12.        });
13.    }          
14.}

This is temporary solution, which is based on the semaphore "IsFiltered". For now this solution will be sufficient.

Regards,
Luke
0
Dimiter Madjarov
Telerik team
answered on 12 Mar 2014, 09:12 AM
Hi Luke,


Thanks for the update. I am not exactly sure what is the current scenario, but as a side, keep in mind that you could also add the filter directly in the dataSource configuration.

I wish you a great day!

Regards,
Dimiter Madjarov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Luke
Top achievements
Rank 1
answered on 14 Mar 2014, 08:49 AM
Hi Dimiter,

Thanks for the advise. Your answer definitely resolved my problem.

Regards,
Luke
Tags
Grid
Asked by
Luke
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Luke
Top achievements
Rank 1
Share this question
or