[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 ?
Codepublic 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})"; }
}
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