Ticket T1161838
Visible to All Users

How to change a dashboard view caption

created 2 years ago (modified 2 years ago)

[DevExpress Support Team: CLONED FROM T1084394: Xaf Blazor - Dashboard View - Count record in nested listiview.]

Hello,

Since the 22.2.5 the the InnerView of the DashboardViewItem in the OnViewControlsCreated is always null.
DxFormLayout component and its items are now accessible for customization since v22.2.5 and I saw that you updated How to show the number of nested List View items in tab captions with the new method. Does it mean that the solution of counting records of tabs in Dashboard view in this ticket is also obsolete from 22.2.5 ?

Code
public class DashboardCtrl : ViewController<DashboardView> { public class BlazorDashboardCaptionController : ViewController<DashboardView> { public BlazorDashboardCaptionController() { TargetViewId = "MainDashboardView"; } protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); foreach(DashboardViewItem item in View.GetItems<DashboardViewItem>()) { if(item.InnerView is ListView listView) { int count = listView.CollectionSource.GetCount(); IModelLayoutViewItem layoutItemModel = FindLayoutItemModel(View.Model.Layout, item.Model); ((IModelLayoutElementWithCaption)layoutItemModel.Parent).Caption = $"{listView.Caption} ({count})"; } } } private IModelLayoutViewItem FindLayoutItemModel( IEnumerable<IModelViewLayoutElement> items, IModelViewItem viewItem) { foreach(IModelViewLayoutElement item in items) { if(item is IEnumerable<IModelViewLayoutElement>) { IModelLayoutViewItem innerItem = FindLayoutItemModel((IEnumerable<IModelViewLayoutElement>)item, viewItem); if(innerItem != null) { return innerItem; } } else if(item is IModelLayoutViewItem layoutViewItem && layoutViewItem.ViewItem == viewItem) { return layoutViewItem; } } return null; } } }

Quite straight forward but this one is working.

C#
public class CountTabRecordInDashboardView : ViewController<DashboardView> { public CountTabRecordInDashboardView() { TargetViewId = "Orders"; } BlazorLayoutManager layoutManager; protected override void OnActivated() { base.OnActivated(); layoutManager = (BlazorLayoutManager)View.LayoutManager; layoutManager.ItemCreated += OnItemCreated; } private void OnItemCreated(object sender, BlazorLayoutManager.ItemCreatedEventArgs e) { BlazorLayoutManager layoutManager = (BlazorLayoutManager)sender; if(e.LayoutControlItem is DxFormLayoutTabPageModel layoutGroup && e.ModelLayoutElement.Parent is IModelTabbedGroup) { foreach(var item in (IModelLayoutGroup)e.ModelLayoutElement) { if(item is IModelLayoutViewItem layoutViewItem && layoutViewItem.ViewItem is IModelDashboardViewItem dashboardViewItem) { if(dashboardViewItem.View is IModelListView modelListView) { int count = View.ObjectSpace.GetObjectsCount(modelListView.ModelClass.TypeInfo.Type, CriteriaOperator.Parse(((IModelListView)dashboardViewItem.View).Criteria)); layoutGroup.Caption = DetailViewControllerHelper.AddItemCountToTabCaption(layoutGroup.Caption, count); } } } } } protected override void OnDeactivated() { if(layoutManager is not null) { layoutManager.ItemCreated -= OnItemCreated; layoutManager = null; } base.OnDeactivated(); } } public static class DetailViewControllerHelper { public static string ClearItemCountInTabCaption(string caption) { int index = caption.IndexOf('('); if(index != -1) { return caption.Remove(index - 1); } return caption; } public static string AddItemCountToTabCaption(string caption, int count) { return $"{caption} ({count})"; } }
Comments (1)
Andrey K (DevExpress Support) 2 years ago

    Hello,

    We will investigate this matter promptly and follow up with you once we have specific information to share. The solution you found looks fine, so you can safely use it

    Thanks,
    Andrey

    Answers approved by DevExpress Support

    created 2 years ago

    Hello,

    Thank you for your patience.

    Starting from v22.2, layout tabs support lazy loading. This is the reason why DashboardViewItem is always null in the OnViewControlsCreated event. You can disable delayed loading of layout tabs by using the CompositeView.DelayedItemsInitialization property:

    C#
    public class DashboardCtrl : ViewController<DashboardView> { public class BlazorDashboardCaptionController : ViewController<DashboardView> { protected override void OnActivated() { base.OnActivated(); View.DelayedItemsInitialization = false; } // } }

    However, your current solution is perfectly fine and should be used in v22.2.5 and higher. The old approach is no longer relevant.

    Thanks,
    Arkady

      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.