Ticket T1084394
Visible to All Users

Xaf Blazor - Dashboard View - Count record in nested listiview.

created 3 years ago

Hi,

I'm trying to get the count of listview in a dashboard view.
Getting the listivew and counting record is not a issue.
I do no know how to access to the tab's caption. Can you help on how to get the captions of the tab ?

First I tried to work with LayoutCreated handler but it seems that i never reaches.

C#
blazorLayoutManager = (BlazorLayoutManager)View.LayoutManager; blazorLayoutManager.LayoutCreated += BlazorLayoutManager_LayoutCreated;

Clipboard-File-1.png

Many thanks
BR
ISA

Comments (2)
DevExpress Support Team 3 years ago

    Hi Isa,

    As far as I understand, you need to implement the same functionality as demonstrated in the following example, but for List Views inside a Dashboard View: XAF - How to show the number of nested List View items in tab captions. Currently, I've not found a way to implement this. Please give us some time to research this possibility.

      Hi Gosha,

      I would like to see the same result yes.
      Thanks for your help.

      BR
      ISA

      Answers approved by DevExpress Support

      created 3 years ago (modified 2 years ago)

      Hello Isa,

      v22.2.5+

      The DxFormLayout component and its items are accessible for customization since v22.2.5 and later. The BlazorLayoutManager.ItemCreated event is triggered when a layout item model is created. By handling this event, you can manage the properties of the following components: DxFormLayout, DxFormLayoutTabPages, DxFormLayoutTabPage, DxFormLayoutGroup, and DxFormLayoutItem.

      You can check how to use the BlazorLayoutManager.ItemCreated event in the following examples:

      Older Versions

      In Detail View models generated by XAF, tab captions are calculated based on inner View Item captions. So, if you update a ListPropertyEditor's caption, the caption of its tab will be updated automatically. EmployeeDetailViewBlazorController uses this behavior to set tab captions.
      In case of a DashboardView, you are creating its model manually in the Model Editor. So, it does not have any calculated values and uses captions that you specify in the Layout designer. To change tab captions in this case, you need to set the captions of the corresponding layout items (WinForms and ASP.NET WebForms) or their models (ASP.NET Core Blazor). Here is an example:

      C#
      using DevExpress.ExpressApp; using DevExpress.ExpressApp.Editors; using DevExpress.ExpressApp.Model; using System.Collections.Generic; namespace MainDemo.Module.Blazor { public class BlazorDashboardCaptionController : ViewController<DashboardView> { public BlazorDashboardCaptionController() { TargetViewId = "Dashboard1"; } protected override void OnActivated() { base.OnActivated(); View.DelayedItemsInitialization = false; } 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; } } }
        Show previous comments (4)

          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})"; } }
            Andrey K (DevExpress Support) 2 years ago

              Hello,

              I created a separate ticket on your behalf: T1161838: How to change a dashboard view caption. We placed it in our processing queue and will process it shortly.

              Thanks,
              Andrey

              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.