Editing a child cell should update the value in a parent cell.

Hi,

I am using a SfTreeGrid and i have an ObservableCollection as my datasource. I would like to know how to refresh the values of all grid cells when one cell changes value. 

The relevant part of my xaml-file looks as follows:

<syncfusion:SfTreeGrid Name="treeGrid"   
 ChildPropertyName="Children"
 ItemsSource="{Binding AllocationToolModel.TreeRows}">
 <syncfusion:SfTreeGrid.StackedHeaderRows>
<syncfusion:StackedHeaderRow>
<syncfusion:StackedHeaderRow.StackedColumns>
<syncfusion:StackedColumn ChildColumns="Weight,ReferencePortfolioWeight,WeightDifference" HeaderText="Weights" />
<syncfusion:StackedColumn ChildColumns="Contribution,ReferencePortfolioContribution,ContributionDifference" HeaderText="Contrib" />
</syncfusion:StackedHeaderRow.StackedColumns>
</syncfusion:StackedHeaderRow>
</syncfusion:SfTreeGrid.StackedHeaderRows>
<syncfusion:SfTreeGrid.Columns>
<syncfusion:TreeGridTextColumn HeaderText="Asset" MappingName="AssetName" Width="240"/>
<syncfusion:TreeGridNumericColumn AllowEditing="True" HeaderText="Pf" MappingName="Weight" UpdateTrigger="PropertyChanged" Width="75" Changed="TreeGridNumericColumn_Changed"/>
<syncfusion:TreeGridNumericColumn AllowEditing="True" HeaderText="RPf" MappingName="ReferencePortfolioWeight" Width="75"/>
<syncfusion:TreeGridNumericColumn MappingName="WeightDifference" HeaderText="Rel" AllowEditing="False" Width="75"/>
<syncfusion:TreeGridNumericColumn HeaderText="Ret" MappingName="ExpectedReturn" Width="75"/>
<syncfusion:TreeGridNumericColumn HeaderText="Pf" MappingName="Contribution" Width="75"/>
<syncfusion:TreeGridNumericColumn HeaderText="RPF" MappingName="ReferencePortfolioContribution" Width="75"/>
<syncfusion:TreeGridNumericColumn MappingName="ContributionDifference" HeaderText="rel" AllowEditing="False" Width="75"/>
</syncfusion:SfTreeGrid.Columns>
</syncfusion:SfTreeGrid>

I would like to use this method to trigger a refresh of the grid. 
private void TreeGridNumericColumn_Changed(object sender, EventArgs e)
{
treeGrid.UpdateLayout();
         //I would assume that something more is needed here? 
}



The "problem" seems to have to do with my observable collection. I will use the weight column as an example where the user is able to edit the weight in the grid for a child row and then the value of the parent should be updated with the new total weight. I would like this update without all rows collapsing. 

public double Weight
{
get 
{
if (Children == null)
return _weight;
else
return Children.Sum(x => x.Weight);
}
set { _weight = value; RaisePropertyChanged("Weight"); }
}

If I click a parent cell after having changed the child cell then the new correct value is shown. 


Regards
Fredrik

5 Replies

VS Vijayarasan Sivanandham Syncfusion Team May 26, 2020 05:00 PM UTC

Hi Fredrik Backstrand,

Thank you for contacting Syncfusion support.

Currently, we are analyzing your requirement of “Editing a child cell should update the value in a parent cell” in SfTreeGrid. We will validate and update you the details on May 28, 2020.
 
 
We appreciate your patience until then. 
 
Regards, 
Vijayarasan S

 



FB Fredrik Bäckstrand June 1, 2020 11:09 AM UTC

It's not a large grid so even a non-efficient solution could be relevant. 

Would it be possible to loop all cells in the grid and "refresh" them one by one? 


VS Vijayarasan Sivanandham Syncfusion Team June 3, 2020 03:39 AM UTC

Hi Fredrik Backstrand,

Sorry for the inconvenience caused.

We are currently working on this and we need two more business days to validate this. We will update you with further details on June 04, 2020.

We appreciate your patience until then. 
 
Regards, 
Vijayarasan S 



VS Vijayarasan Sivanandham Syncfusion Team June 5, 2020 03:58 AM UTC

Hi Fredrik Backstrand

Sorry for the inconvenience caused.

We are preparing workaround based on provided information to achieve your requirement, but we are facing some technical issue in achieve your requirement.
So, we need one more business day to validate this. We will update you with further details on June 05, 2020.

We appreciate your patience until then. 
 
Regards, 
Vijayarasan S 



VS Vijayarasan Sivanandham Syncfusion Team June 7, 2020 11:49 AM UTC

Hi Fredrik Backstrand,

Thank you for your patience,

Your requirement can be achieved by customizing the SfTreeGrid.CurrentCellEndEdit event in SfTreeGrid. Please refer the below code snippet,

 
this.treeGrid.CurrentCellEndEdit += TreeGrid_CurrentCellEndEdit;

double total = 0;

private void TreeGrid_CurrentCellEndEdit(object sender, Syncfusion.UI.Xaml.Grid.CurrentCellEndEditEventArgs e) 
{             
            var childNode = this.treeGrid.GetNodeAtRowIndex(e.RowColumnIndex.RowIndex); 
            //if more than one parent node is achieved ,you need to check those levels  
            for (int i = childNode.Level; i > 0; i--) 
            { 
                CheckChildNode(childNode.ParentNode); 
                childNode = childNode.ParentNode; 
            }                  
} 
 
private void CheckChildNode(TreeNode treeNode) 
{ 
            //Check whether the treeNode is null or not 
            if (treeNode != null) 
            { 
                var p = treeNode.Item as Employee; 
                if (treeNode.ChildNodes.Count != 0) 
                { 
                    //if more than one treeNode is achieved ,you need to check those levels  
                    foreach (var childNode in treeNode.ChildNodes) 
                    {   
                        //Called recursively , to traverse it inner level of group. 
                        CheckChildNode(childNode); 
                    } 
                } 
                else 
                { 
                    total = p.Salary + total; 
                } 
                p.Salary = total; 
                total = 0; 
            } 
} 
Regards,
Vijayarasan S
 


Loader.
Up arrow icon