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

Unable to find the TableSummaryRow index in SfDataGrid's TableSummaryRows for style customisation

Hello,

I'm trying to apply a different style on the last TableSummaryRow. For that, I used the TableSummaryRowStyleSelector="{StaticResource tableSummaryRowStyleSelector}"  property on the SfDataGrid. 
In the "SelectStyle(object item, DependencyObject container)" method in my style selector class, I am unable to get the information about the row position of the current row in SfDataGrid's TableSummaryRows: container is a Syncfusion.UI.Xaml.Grid.TableSummaryRowControl and item is a Syncfusion.UI.Xaml.Grid.SpannedDataRow

Is there a way to get that info ?

Many Thanks,
Anas

3 Replies

FP Farjana Parveen Ayubb Syncfusion Team June 19, 2015 11:32 AM UTC

Hi Anas,


Thank you for contacting Syncfusion support.


We analyzed your query and you can achieve your requirement “Customize the TableSummaryRowStyle based on the TableSummary row index” by getting the row index from the SpannedDataRow in StyleSeletor.


Please refer the code example and sample in the following location:


Code Snippet (XAML):


  <syncfusion:SfDataGrid x:Name="sfdatagrid" 

                               AllowEditing="True"

                               AutoGenerateColumns="False"

                               TableSummaryRowStyleSelector="{StaticResource tableSummaryStyleSelector}"
                               ItemsSource="{Binding Path=Products}" >


Code Snippet(C# - StyleSelector):


class TableSummaryStyleSelector : StyleSelector

    {

        public override Style SelectStyle(object item, DependencyObject container)

        {

            var data = item as SpannedDataRow;

            var index = data.RowIndex;

            if (index == 1)

                return App.Current.Resources["TableSummaryStyle1"] as Style;

            return App.Current.Resources["TableSummaryStyle2"] as Style;

        }
    }


Sample Location: TableSummaryRowStyle


If your requirement is differ from this could you please share the exact requirement that will help us to provide the solution in better way.


Regards,

Farjana Parveen A



AE Anas El Hallabi June 19, 2015 11:56 AM UTC

Hello Farjana Parveen A,

Thanks you for your answer.
Actually, I was aware of the RowIndex property of the spannedDataRow but in my situation, i don't know how many TableSummaryRows are actually beeing displayed in the sfdatagrid.
Thanks to debugger, i noticed that SpannedDataRow had an internal property "DataGrid" which refer to the grid. Using reflexion i managed to get it and so, the TableSummaryRows property as in code below:

var dataGrid = typeof(SpannedDataRow).GetProperty("DataGrid", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(tItem) as SfDataGrid;

var currentSummaryRow = (tItem.RowData as Syncfusion.Data.SummaryRecordEntry).SummaryRow as GridTableSummaryRow;

if (dataGrid != null && dataGrid.TableSummaryRows.Any() && dataGrid.TableSummaryRows.Last() == currentSummaryRow)
        isTheLastDisplayedRow = true;

This made the trick, thank you again for your support.

Anas


SC Saranya CJ Syncfusion Team June 22, 2015 07:02 AM UTC

Hi Anas,
Thank you for your update. Please let us know if you require any other assistance.
Regards,
Saranya

Loader.
Live Chat Icon For mobile
Up arrow icon