How to get PivotGridRowHeaderCell parent

5 posts, 0 answers
  1. Barbaros Saglamtimur
    Barbaros Saglamtimur avatar
    110 posts
    Member since:
    Jul 2012

    Posted 03 May 2013 Link to this post

    Hi,

    I would like get  PivotGridRowHeaderCell's parent in CellDataBound event. For visual explanation see attached image.

    TIA
  2. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 08 May 2013 Link to this post

    Hello,

    This is achievable by obtaining a reference to the ParentIndexes collection of the PivotGridRowHeaderCell. It returns an array of the names of parent fields of a given header cell.

    Regards,
    Angel Petrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Barbaros Saglamtimur
    Barbaros Saglamtimur avatar
    110 posts
    Member since:
    Jul 2012

    Posted 15 May 2013 Link to this post

    Thanks for your reply,
    I already found it, but ParentIndexes returns array of DataItems, I need field properties as-well. So List<PivotGridCell> would be super.
  5. Angel Petrov
    Admin
    Angel Petrov avatar
    1006 posts

    Posted 20 May 2013 Link to this post

    Hi Barbaros,

    I am sorry to say but with the current implementation of the control returning a list of PivotGridCells is not possible. What you can do is access the field like demonstrated in the code snippet below:
    protected void RadPivotGrid2_CellDataBound(object sender, PivotGridCellDataBoundEventArgs e)
        {
            if (e.Cell is PivotGridRowHeaderCell)
            {
                PivotGridRowHeaderCell cell = e.Cell as PivotGridRowHeaderCell;
                List<PivotGridField> rowFields = RadPivotGrid2.Fields.Where(x=>x is PivotGridRowField).ToList();
                rowFields.OrderBy(x => x.ZoneIndex);
                int index=rowFields.IndexOf(cell.Field);
                PivotGridField field = rowFields[index - 1];
            }
        }


    All the best,
    Angel Petrov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Barbaros Saglamtimur
    Barbaros Saglamtimur avatar
    110 posts
    Member since:
    Jul 2012

    Posted 20 May 2013 Link to this post

    Thanks for your reply. I have already achieved my goal with the following code ( on CellDataBound event)
    if (e.Cell is PivotGridRowHeaderCell)
    {
                        var parents = ((PivotGridHeaderCell)(e.Cell)).ParentIndexes;
                        Dictionary<int, string> theParentsDict = new Dictionary<int, string>();
                        Dictionary<int, PivotGridField> theFieldsDict = new Dictionary<int, PivotGridField>();
                        theParentsDict =
                            parents.Select((p, index) => new {Index = index, DataItem = p})
                                   .ToDictionary(k => k.Index, v => v.DataItem.ToString());
                        theFieldsDict =
                            RadPivotGrid1.Fields.GetFieldsByType("PivotGridRowField")
                                         .Where(f => !f.IsHidden)
                                         .Select(f=> new {Index = f.ZoneIndex, DataField = f})
                                         .ToDictionary(k => k.Index, v => v.DataField);
                        Dictionary<int, PivotGridField> rowItems = (from p in theParentsDict
                                                              join f in theFieldsDict
                                                                  on p.Key equals f.Key
                                                                    select new
                                                              {
                                                                  Index = p.Key,
                                                                  RowField = f.Value,
                                                              }).ToDictionary(k => k.Index, v => v.RowField);
    }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017