Exemple #1
0
        private void FlatternGroups(List <object> rows, GroupedItem parent, Group parentGroup, int?parentLevel)
        {
            List <object> items;
            int?          level = parentLevel == null ? 0 : parentLevel.Value + 1;

            if (parent != null)
            {
                items = parent.ChildItems;
            }
            else
            {
                items = _items;
            }

            List <object> rowsToAdd = new List <object>();

            List <object> sortedItems = new List <object>(items);

            for (int i = 0; i < items.Count; i++)
            {
                sortedItems[i] = items[i];
            }
            if (_sortColumn != null)
            {
                SortBy(_sortColumn, sortedItems);
            }

            foreach (object item in sortedItems)
            {
                GroupedItem groupedItem = (GroupedItem)item;

                // Is the item a group?
                if ((string)Script.Literal("typeof({0})", groupedItem.ChildItems) != "undefined")
                {
                    // Is the group expanded or collapsed?

                    // Add group
                    string groupingKey = (parent != null ? parent.Id : "") + "|" + groupedItem.Id;
                    Group  group;
                    if (groups.ContainsKey(groupingKey))
                    {
                        group = groups[groupingKey];
                    }
                    else
                    {
                        group = new Group();
                        groups[groupingKey] = group;
                    }
                    group.Title       = groupedItem.Title.ToString();
                    group.Rows        = new List <object>();
                    group.GroupingKey = groupingKey;

                    bool collapsed = false;

                    if (_groupStates.ContainsKey(groupingKey))
                    {
                        collapsed = _groupStates[groupingKey];
                    }
                    else
                    {
                        _groupStates[groupingKey] = collapsed;
                    }

                    group.Level = level.Value;
                    rowsToAdd.Add(group);
                    group.Count     = rows.Count + rowsToAdd.Count;
                    group.Collapsed = collapsed;

                    if (!collapsed)
                    {
                        // Add child rows
                        FlatternGroups(rowsToAdd, groupedItem, group, level);
                    }
                }
                else
                {
                    // Just add the item
                    rowsToAdd.Add(item);
                }
            }


            rows.AddRange(rowsToAdd);
        }
Exemple #2
0
        private void FlatternGroups(List<object> rows, GroupedItem parent,Group parentGroup, int? parentLevel)
        {
            List<object> items;
            int? level = parentLevel==null ? 0 : parentLevel.Value+1;
            if (parent!=null)
            {
                items = parent.ChildItems;
            }
            else
            {
                items = _items;
            }

            List<object> rowsToAdd = new List<object>();
           
            List<object> sortedItems = new List<object>(items);
            for (int i = 0; i < items.Count; i++)
            {
                sortedItems[i] = items[i];
            }
            if (_sortColumn != null)
                SortBy(_sortColumn, sortedItems);

            foreach (object item in sortedItems)
            {
                GroupedItem groupedItem = (GroupedItem)item;
              
                // Is the item a group?
                if ((string)Script.Literal("typeof({0})", groupedItem.ChildItems) != "undefined")
                {
                    // Is the group expanded or collapsed?

                    // Add group
                    string groupingKey = (parent!=null ? parent.Id : "") + "|" + groupedItem.Id;
                    Group group;
                    if (groups.ContainsKey(groupingKey))
                    {
                        group = groups[groupingKey];
                    }
                    else
                    {
                        group = new Group();
                        groups[groupingKey] = group;
                    }
                    group.Title = groupedItem.Title.ToString();
                    group.Rows = new List<object>();
                    group.GroupingKey = groupingKey;
                   
                    bool collapsed = false;

                    if (_groupStates.ContainsKey(groupingKey))
                    {
                        collapsed = _groupStates[groupingKey];
                    }
                    else
                    {
                        _groupStates[groupingKey] = collapsed;
                    }

                    group.Level = level.Value;
                    rowsToAdd.Add(group);
                    group.Count = rows.Count + rowsToAdd.Count;
                    group.Collapsed = collapsed;

                    if (!collapsed)
                    {
                        // Add child rows
                        FlatternGroups(rowsToAdd, groupedItem, group, level);
                        
                    }

                }
                else
                {
                    // Just add the item
                    rowsToAdd.Add(item);
                   

                }
            }

           
            rows.AddRange(rowsToAdd);

        }