Aggregate custom has a conflict with cell edit

Hi,

Here is my code:

@using Syncfusion.Blazor.Grids


<SfGrid @ref="Grid" DataSource="@Products" AllowPaging="true">
    <GridEditSettings AllowEditing=true AllowEditOnDblClick=true Mode="EditMode.Batch" />
    <GridAggregates>
        <GridAggregate>
            <GridAggregateColumns>
                <GridAggregateColumn Field=@nameof(Product.TotalSales) Type="AggregateType.Custom">
                    <FooterTemplate>
                        @{
                            <div>
                                <p>Custom: @GetWeightedAggregate()</p>
                            </div>
                        }
                    </FooterTemplate>
                </GridAggregateColumn>
            </GridAggregateColumns>
        </GridAggregate>
    </GridAggregates>
    <GridColumns>
        <GridColumn Field=@nameof(Product.ProductName) HeaderText="Product Name" TextAlign="TextAlign.Right" AllowEditing=false Width="150"></GridColumn>
        <GridColumn Field=@nameof(Product.QuantityPerUnit) HeaderText="Quantity Per Unit" Width="150" AllowEditing=false></GridColumn>
        <GridColumn Field=@nameof(Product.TotalSales) HeaderText="TotalSales" TextAlign="TextAlign.Right" Width="130"></GridColumn>
        <GridColumn Field=@nameof(Product.TotalCosts) HeaderText="TotalCosts" TextAlign="TextAlign.Right" AllowEditing=false Width="180"></GridColumn>
    </GridColumns>
</SfGrid>


@code{
    SfGrid<Product> Grid { get; set; }
    public List<Product> Products { get; set; }
    public string GetWeightedAggregate()
    {
        // Here, you can calculate custom aggregate operations and return the result.
        return Queryable.Sum(Products.Select(x => (x.TotalSales + x.TotalCosts) / x.TotalSales).AsQueryable()).ToString();
    }
    protected override void OnInitialized()
    {
        Products = Enumerable.Range(1, 5).Select(x => new Product
        {
            ProductName = (new string[] { "Chai", "Chang", "Aniseed Syrup", "Chef Anton's Cajun Seasoning", "Chef Anton's Gumbo Mix" })[new Random().Next(5)],
            QuantityPerUnit = (new string[] { "10 boxes x 20 bags", "24 - 12 oz bottles", "12 - 550 ml bottles", "48 - 6 oz jars", "36 boxes" })[new Random().Next(5)],
            TotalSales = 100 * x,
            TotalCosts = 200 * x,
            Discontinued = (new bool[] { true, false })[new Random().Next(2)]
        }).ToList();
    }


    public class Product
    {
        public string ProductName { get; set; }
        public string QuantityPerUnit { get; set; }
        public int TotalSales { get; set; }
        public int TotalCosts { get; set; }
        public bool Discontinued { get; set; }
    }
}

This is how it looks like:


I want to edit TotalSales so I doubleclick the first cell. I change it to 200.

Then I press enter. The textbox doesn't disappear.

I click somewhere else and the textbox disappears this time but the value is not updated.

If I click the same cell again, I actually see the updated value.


Is there anything that I'm doing wrong?


3 Replies

RS Renjith Singh Rajendran Syncfusion Team June 21, 2022 09:07 AM UTC

Hi Adem,


Greetings from Syncfusion support.


We have analyzed your shared codes and we could see that you have not enabled IsPrimaryKey property in your shared codes. We would like to inform you that CRUD operation in Grid will take place only based on the unique PrimaryKey column value. So IsPrimaryKey property must be enabled to any one of the unique valued column defined in grid. Only based on primary key value, the CRUD will be properly performed in Grid.


Please refer the below documentation and check this case from your side.

https://blazor.syncfusion.com/documentation/datagrid/editing


Please get back to us if you need further assistance.


Regards,

Renjith R





AS Adem Sahin replied to Renjith Singh Rajendran June 21, 2022 05:57 PM UTC

Hi Renjith,


Thanks for your support. That was the problem indeed.



RS Renjith Singh Rajendran Syncfusion Team June 22, 2022 06:04 AM UTC

Hi Adem,


Thanks for your update. We are closing this ticket for now. Please create new tickets if you need assistance on new queries.


Regards,

Renjith R



Loader.
Up arrow icon