Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
800
expand from code-behind bug: IsTotal not set correctly
posted

Hi,

I think I have found a bug in the IOlapViewModel (or in sample programs). I have used sample code from this forum and the sample programs in the blogs, online samples.

The issue is that is I expand all hierarchies from code-behind (code #1), then the columns/rows are not correctly identified (code #2) because the IsTotal is still set to True, even if everything is expanded.

Code #1:

public static void ExpandAllFlat(IOlapViewModel model)
        {
            var dataSource = model as DataSourceBase;
            for (int i = 0; i < dataSource.Rows.Count; i++)
            {
                IFilterViewModel fvm = dataSource.Rows[i] as IFilterViewModel;
                if (fvm != null && fvm.FilterMembers != null)
                {
                    foreach (IFilterMember member in fvm.FilterMembers)
                    {
                        DrillInFlat(fvm, member);
                    }
                }
            }
            for (int i = 0; i < dataSource.Columns.Count; i++)
            {
                IFilterViewModel fvm = dataSource.Columns[i] as IFilterViewModel;
                if (fvm != null && fvm.FilterMembers != null)
                {
                    foreach (IFilterMember member in fvm.FilterMembers)
                    {
                        DrillInFlat(fvm, member);
                    }
                }
            }
            //            worker.RunWorkerCompleted += (s, e) => this.PivotGrid.DataSource.RefreshGrid(); ;
            //            worker.RunWorkerAsync(this.PivotGrid.DataSource);
            model.RefreshGrid();
        }

        private static void DrillInFlat(IFilterViewModel filterViewModel, IFilterMember filterMember)
        {
            if (filterMember.IsExpanded == false)
            {
                /*                if (filterMember.Member.LevelDepth > 1)
                                    return; */

                filterMember.IsExpanded = true;
            }

            foreach (IFilterMember member in filterMember.FilterMembers)
            {
                DrillInFlat(filterViewModel, member);
            }
        }

 

Code #2:

 

        public static List<RowColumnIdentity> DetermineRows(IOlapViewModel olapVM, bool WantTotals, bool WantMeasures)
        {
            if (olapVM.Result.RowAxis.Tuples.Count == 0 ||
                olapVM.Result.RowAxis.Tuples[0].Members.Count == 0)
                return null;

            int rowLevel = olapVM.Result.RowAxis.Tuples[0].Members[0].LevelDepth;
            bool dontAdd = false;
            int counter = 0;

            List<RowColumnIdentity> validRows = new List<RowColumnIdentity>();

            for (int tupleCount = 0; tupleCount < olapVM.Result.RowAxis.Tuples.Count; tupleCount++)
            {
                var tuple = olapVM.Result.RowAxis.Tuples[tupleCount];

                if (tuple.IsTotal == false || WantTotals == true)
                {
                    List<RowColumnIdentity> tempRows = new List<RowColumnIdentity>();
                    dontAdd = false;

                    for (int memberCount = 0; memberCount < tuple.Members.Count; memberCount++)
                    {
                        var member = tuple.Members[memberCount];

                        //                    if (member.LevelDepth == rowLevel)
                        if (member.IsTotal == false || WantTotals == true)
                        {
                            if (member.ParentLevel != null)
                                tempRows.Add(new RowColumnIdentity(counter, member.Caption, member.ParentLevel.ParentHierarchy.Name, member.IsTotal, member.LevelName == ""));
                            else
                                if (WantMeasures) tempRows.Add(new RowColumnIdentity(counter, member.Caption, member.Name, member.IsTotal, member.LevelName == "")); // tupleCount * (tuple.Members.Count) + memberCount
                        }
                        else
                        {
                            dontAdd = true;
                            break;
                        }
                    }
                    if (!dontAdd)
                    {
                        validRows.AddRange(tempRows);
                    }
                }
                counter++;
            }

            return validRows;
        }

 

If I expand the node manually by pressing all the expanders on a PivotGrid that is linked to the datasource, then the determination of columns and rows works fine.

Can you please check this?

Thanks and best regards,

Tamas