Ticket T152492
Visible to All Users

How to set PivotGridControl.OptionsBehavior.UseAsyncMode to True for the first data load

created 10 years ago

I would like to enable AsyncMode for all my PivotGrids, because mostly the contains enormous amount of data and working without AsyncMode looks strange from end-user perspective. I was following this ticket http://www.devexpress.com/Support/Center/Question/Details/Q324108 and set the OptionsBehavior.UseAsyncMode property to True.

C#
public class PivotGridController : ObjectViewController<ListView, CapacityCubeItem> { protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); PivotGridListEditor listEditor = View.Editor as PivotGridListEditor; if (listEditor != null) { if (listEditor.PivotGridControl == null) { listEditor.ControlsCreated += listEditor_ControlsCreated; } else { SetupPivotGridControl(listEditor.PivotGridControl); } } } void listEditor_ControlsCreated(object sender, EventArgs e) { SetupPivotGridControl((PivotGridControl)sender); } private void SetupPivotGridControl(PivotGridControl pivotGridControl) { pivotGridControl.OptionsBehavior.UseAsyncMode = true; } }

Everything works perfectly with one significant exception. When PivotGridControl is initialized for the first time, data are loaded before I can switch its behavior to AsyncMode. Is there any way how to make control use AsyncMode right away (including its initialization). It looks very ugly now, when end-user opens ListView or DetailView containing the PivotGridControl and entire GUI freez like something is broken for a long time (until data are loaded).

Thank you for any advice.

Answers approved by DevExpress Support

created 10 years ago

Hello Martin.

I have researched this issue found that it cannot be easily avoided. The ListEditor.ControlsCreated event is raised after the underlying contols are created and the data source is assigned to them, i.e. after the initial delay. Anyway, the UseAsyncMode cannot affect this delay, because it is considered by user-initiated operations only. To make the control responsive when it processes the initial layout, you need to create a custom PivotGridListEditor descendant and use the PivotGridControl.SetDataSourceAsync method instead of directly assigning the DataSource property. Here is an example:

C#
[ListEditor(typeof(object), false)] public class PivotGridListEditorEx : PivotGridListEditor { public PivotGridListEditorEx(IModelListView model) : base(model) { } public override void ApplyModel() { base.ApplyModel(); } protected override object CreateControlsCore() { var c = base.CreateControlsCore(); this.PivotGridControl.OptionsBehavior.UseAsyncMode = true; return c; } public override void Refresh() { if (this.PivotGridControl != null) { if (base.List is DevExpress.Data.IListServer) { throw new Exception("The PivotGridListEditor doesn't support Server Mode and so cannot use an IListServer object as the data source."); } this.PivotGridControl.SetDataSourceAsync(base.List); } if (this.Control == null) return; var layoutControl = (XafLayoutControl)this.Control; var chartLayoutItem = layoutControl.GetItemByControl(this.ChartControl); if (chartLayoutItem != null && chartLayoutItem.Visibility == LayoutVisibility.Always) { this.ChartControl.DataSource = this.PivotGridControl; this.ChartControl.SeriesDataMember = "Series"; this.ChartControl.SeriesTemplate.ArgumentDataMember = "Arguments"; this.ChartControl.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Values" }); this.ChartControl.RefreshData(); } } }

Note that the above solution frees the UI thread only while the PivotGrid processes data. The CollectionSource still loads data from the database synchronously on the UI thread.

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.