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

Binding to calculated fields

3 Answers 61 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 19 Sep 2011, 04:13 PM
Please note this is not about fields calculated by the grid, but how the grid binds fields that are calculated in a model class.

I'm trying to improve performance on a gridview control that is bound to a collection of business objects. Each object has many calculated fields. The fields are all calculated prior to the data being loaded and the grid being displayed, but I'm finding that the control is constantly 'getting' the calculated fields, causing the (sometimes expensive) calculations to be performed again.

Is there a setting or design practice that can make this more efficient?

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 21 Sep 2011, 12:37 PM
Hi Marc,

Most of the operations performed when displaying data in RadGridView are based on bindings.
When scroll, sort , group and other data shaping operations are performed , cells are being recreated and bindings set. This causes the getters of your view model properties to be invoked.

If the getters are heavy  the recommended approach would be to use caching of the values at your view model.

Greetings,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Marc
Top achievements
Rank 1
answered on 21 Sep 2011, 03:04 PM
Pavel

Thanks. I have tried to implement some caching, but I not sure if it the most efficient way. Would you have an example of the best way to cache this for the gridview control?
0
Pavel Pavlov
Telerik team
answered on 26 Sep 2011, 03:18 PM
Hello Marc,

I meant something like :
            private object myProperty;
        public object MyProperty
        {
            get
            {
                if (this.myProperty == null)
                {
                    this.myProperty = CalculateMyProperty();
                }
                return this.myProperty;
            }
        }

Actually nothing fancy. Just taking care for the heavy logic ( in this case CalculateMyProperty)  to be executed once and not on every single call of the getter.

Regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Marc
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Marc
Top achievements
Rank 1
Share this question
or