We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Modifying Stacked Headers programatically - changes not reflected for new columns

I can successfully modify an existing Stacked Header column.

However if I add a new Stacked Header column in code, the changes are not visible.

eg:

View Model - initialise GridData property:

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

            data.Add(new TestDataRow()

            {

                HowMany = 2,

                Name = "Chickens",

                When = new DateTime(2014, 4, 16)

            });

            data.Add(new TestDataRow()

            {

                HowMany = 5,

                Name = "Ducks",

                When = new DateTime(2015, 3, 12)

            });

            GridData = new ObservableCollection<object>(data);


View - sfDataGrid:

            <syncfusion:SfDataGrid x:Name="DataGrid"
                Grid.Column="0" Grid.Row="0" ItemsSource="{Binding GridData}"
            AutoGenerateColumns="True"  AllowResizingColumns="True"
                               AllowEditing="False"
                               SelectionUnit="Row" IsEnabled="{Binding IsNotLoading}">
                <syncfusion:SfDataGrid.StackedHeaderRows>
                    <syncfusion:StackedHeaderRow>
                        <syncfusion:StackedHeaderRow.StackedColumns>
                            <syncfusion:StackedColumn  HeaderText="ONE" ChildColumns="Name"/>
                        </syncfusion:StackedHeaderRow.StackedColumns>
                    </syncfusion:StackedHeaderRow>
                </syncfusion:SfDataGrid.StackedHeaderRows>
            </syncfusion:SfDataGrid>


Code-behind - modify stacked header (click, on a test button):

            var childColToAdd = new StackedColumn();
            this.DataGrid.StackedHeaderRows[0].StackedColumns.Add(childColToAdd);
            var childCol = this.DataGrid.StackedHeaderRows[0].StackedColumns[0].ChildColumns;
            // modify first
            this.DataGrid.StackedHeaderRows[0].StackedColumns[0].ChildColumns = childCol + ",When";
            // modify second - added above - this does not work
            this.DataGrid.StackedHeaderRows[0].StackedColumns[1].ChildColumns = "qty";

The first modification does work - the second does not - BUT if I click on the qty column, in the middle, it changes the sort order - correctly.  If I then click above the text "qty" it does not change the sort order, as if the stacked column has been added but can't be seen.



3 Replies

JG Jai Ganesh S Syncfusion Team July 29, 2015 03:01 AM UTC

Hi Stephen,

Thank you for using Syncfusion products.

We have analyzed your query with your code snippet. In that you have modified the existing stacked header row by add the column name that is in underlying collection. Hence it worked properly but at second you gave the column name “qty” and it is not in the underlying collection. Hence it not worked. In SfDataGrid every operations (Sorting, Filtering, Grouping etc..) are worked based on the MapingName that is in the underlying collection. So could you please give the stacked column name as in the underlying collection in your application.

Please let us know if you need further assistance.

Thank you,
Jai Ganesh S


ST Stebay July 30, 2015 09:36 AM UTC

Hi Jai Ganesh S

I've found the source of my issue - the column I was adding the Stacked Header for was named HowMany, but the entity also had an attribute specifying the display name:
            [Display(Name = "qty")]
            public int HowMany { get; set; }

I was assuming the column name would therefore be "qty" but I see that the grid uses the original entity property name as the column name, but does use the Display - Name attribute for the header text.

So this is all working fine for me, thank you.

Regards
Steve


JS Jayapradha S Syncfusion Team July 30, 2015 09:53 AM UTC

Hi Steve,

We are glad to know that your issue has been resolved.

Please let us know if you have any other queries.

Regards,
Jayapradha

Loader.
Live Chat Icon For mobile
Up arrow icon