Template is lost when FieldReorder command is fired

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

    Posted 15 May 2013 Link to this post

    Hi,

    I have CellTemplate for each PivotGridRowField which is an User Control. For the first load everything works fine, but when I reorder, template is lost and instead cell normal text is displayed. Please download project from below link to see how it happens. Just replace ItemGroup with InventSite using "Drag to Reorder", you will see ItemGroup is not using template. But after than, if you expand any of ItemGroup it binds to template again. I am using version 2013.1.417.40

    Download link
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 20 May 2013 Link to this post

    Hi Barbaros,

    Thank you for reporting this issue.

    It appears that this problematic behavior is a bug in the RadPivotGrid control which I already logged in our tracking system. Our dev team will do their best to isolate its root cause and provide a fix as soon as possible.

    All the best,
    Maria Ilieva
    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 12 Jun 2013 Link to this post

    So, problem still persists @ 2013.2.611.
  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 17 Jun 2013 Link to this post

    Hi Barbaros,

    Our dev team was not able to provide the fix for the past official release, however they ensured me it will be available for the next SP1 release.
    Excuse us for any inconvenience this issue may lead.

    Regards,
    Maria Ilieva
    Telerik
    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 the blog feed now.
  6. Barbaros Saglamtimur
    Barbaros Saglamtimur avatar
    110 posts
    Member since:
    Jul 2012

    Posted 12 Aug 2013 Link to this post

    It's 2013.2.806.x and problem still alive. Any news?

    TIA
  7. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 15 Aug 2013 Link to this post

    Hi Barbaros,

    The mentioned bug fix is still in research phase. However it is added in the planning for this Q and a fix should be available in the upcoming official release.

    Excuse us for any inconvenience this issue may lead.

    Regards,
    Maria Ilieva
    Telerik
    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 the blog feed now.
  8. Tim
    Tim avatar
    85 posts
    Member since:
    Aug 2008

    Posted 05 Nov 2013 Link to this post

    I have a work-around that should work for everyone.  I've only spent about 2hrs on it, so maybe there are some use-cases I haven't covered, but this seems to work for me no matter how I re-order the column/row fields.

    You will need to hook into the PivotGrid's OnInit and OnAddingFieldToZone events.  There are also two variables to keep track of during every PostBack.

    Step 1:
    First, let's cover the variables.  We need to keep track of the original Templates for any Row/Column field during the OnInit event.  This has to be done here and not in the OnItemCommand event because by the time it reaches that event with a CommandName="FieldReorder", it's already too late and sometimes (but not always) the Field's have already lost their templates.

    VB.NET
    Private pivotFieldTemplates As Dictionary(Of String, ITemplate)
     
    Protected Sub PivotGrid_Init(sender As Object, e As EventArgs)
        'Cache the Field templates in case they are lost during the 'AddingFieldToZone' event.
        'NOTE: This is a bug with Telerik at least up to version 2013.2+.
        'Even though there is only one Column being reordered, it can still lose the Templates from others.
        Dim grid = DirectCast(sender, RadPivotGrid)
        Dim templates = ( _
            From f In grid.Fields
            Where (TypeOf f Is PivotGridRowField) OrElse (TypeOf f Is PivotGridColumnField)
            Select New With { _
                .Field = f.UniqueName, _
                .Template = If(TypeOf f Is PivotGridRowField, _
                                CType(f, PivotGridRowField).CellTemplate, _
                                CType(f, PivotGridColumnField).CellTemplate _
                            )
            }) _
            .ToDictionary(Function(f) f.Field, Function(f) f.Template)
        Me.pivotFieldTemplates = templates
    End Sub

    C#:
    private Dictionary<string, ITemplate> pivotFieldTemplates;
     
    protected void PivotGrid_Init(object sender, EventArgs e)
    {
        /*Cache the Field templates in case they are lost during the 'AddingFieldToZone' event.
        NOTE: This is a bug with Telerik at least up to version 2013.2+.
        Even though there is only one Column being reordered, it can still lose the Templates from others.*/
        var grid = (RadPivotGrid)sender;
        var templates = (
            from f in grid.Fields
            where (f is PivotGridRowField) || (f is PivotGridColumnField)
            select new {
                Field = f.UniqueName,
                Template = (f is PivotGridRowField
                        ? ((PivotGridRowField)f).CellTemplate
                        : ((PivotGridColumnField)f).CellTemplate
                        )
            })
            .ToDictionary(f =>f.Field, f => f.Template);
        this.pivotFieldTemplates = templates;
    }

    Step 2:
    Now we need to handle the OnItemCommand event.  In this event, we're simply going to check if the "FieldReorder" command has fired.  This requires another variable to keep track of that.

    VB.NET:
    Private hasPivotFieldsReordered As Boolean
     
    Protected Sub PivotGrid_ItemCommand(sender As Object, e As PivotGridCommandEventArgs)
        Me.hasPivotFieldsReordered = (e.CommandName = "FieldReorder")
    End Sub

    C#:
    private bool hasPivotFieldsReordered;
     
    protected void PivotGrid_ItemCommand(sender As Object, e As PivotGridCommandEventArgs)
    {
        this.hasPivotFieldsReordered = (e.CommandName == "FieldReorder")
    }

    Step 3:
    Now, we need to handle the PivotGrid's OnAddingFieldToZone event.  In this event, we need to check if any "Reordering" has ocurred (we don't really care which Field was reordered, because sometimes other Fields lose their templates as well).

    VB.NET:
    Protected Sub PivotGrid_AddingFieldToZone(sender As Object, e As PivotGridAddingFieldToZoneEventArgs)
        'If a Field Reorder happened, need to make sure all Templates are re-applied to each Field
        'NOTE: See PivotGrid's 'ItemCommand' event for more info...
        If (Me.hasPivotFieldsReordered AndAlso Me.pivotFieldTemplates.ContainsKey(e.Field.UniqueName)) Then
            If (TypeOf e.Field Is PivotGridRowField) Then
                CType(e.Field, PivotGridRowField).CellTemplate = Me.pivotFieldTemplates(e.Field.UniqueName)
            ElseIf (TypeOf e.Field Is PivotGridColumnField) Then
                CType(e.Field, PivotGridColumnField).CellTemplate = Me.pivotFieldTemplates(e.Field.UniqueName)
            End If
        End If
    End Sub

    C#:
    protected void PivotGrid_AddingFieldToZone(object sender, PivotGridAddingFieldToZoneEventArgs e)
    {
        /*If a Field Reorder happened, need to make sure all Templates are re-applied to each Field
        NOTE: See PivotGrid's 'ItemCommand' event for more info... */
        if (this.hasPivotFieldsReordered && this.pivotFieldTemplates.ContainsKey(e.Field.UniqueName)) {
            if (e.Field is PivotGridRowField)
                ((PivotGridRowField)e.Field).CellTemplate = this.pivotFieldTemplates[e.Field.UniqueName];
            else if (e.Field is PivotGridColumnField)
                ((PivotGridColumnField)e.Field).CellTemplate = this.pivotFieldTemplates[e.Field.UniqueName];
        }
    }

    Annnnnd viola!
  9. Barbaros Saglamtimur
    Barbaros Saglamtimur avatar
    110 posts
    Member since:
    Jul 2012

    Posted 06 Nov 2013 Link to this post

    Hi Tim,

    Thanks for your workaround. I can confirm that it works. Although this solves my problem I did not mark it as answer because I am waiting for telerik to fix it. Anyway, I really appreciate your help.  
  10. Tim
    Tim avatar
    85 posts
    Member since:
    Aug 2008

    Posted 06 Nov 2013 Link to this post

    Sure, glad to help.  Just an update, I have removed the variable "hasPivotFieldsReordered" and now just re-assign the Templates on each PostBack in the OnAddingFieldToZone event.  I had started noticing that when moving RowFields to Columns, that SOMETIMES it wasn't retaining the Template on subsequent PostBacks.  So this seems like an issue in general with the PivotGrid that when a Field is moved from being a Row to a Column field, or visa-versa, that the Template is not being retained.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017