how to Sum Row without lost focus with Grid Batch Edit Mode and numberictextbox

Hi,

here is my code:

<SfGrid DataSource="@gridBanHang">

    <GridEditSettings Mode="EditMode.Batch"></GridEditSettings>

    <GridColumns>

        <GridColumn Field=@nameof(SanPhamModel.Id) HeaderText="ID" AllowEditing="false" TextAlign="TextAlign.Right" Visible="false"></GridColumn>

        <GridColumn Field=@nameof(SanPhamModel.TenSanPham) HeaderText="Tên Sản Phẩm" AllowEditing="false"></GridColumn>

        <GridColumn Field=@nameof(SanPhamModel.Gia) HeaderText="Giá" Format="N2">

            <Template>

                @{


                    var item = context as SanPhamModel;

                    double min;

                    if (item.Id == 399 || item.Id == 398)

                    { min = double.MinValue; }

                    else

                    { min = 0; }

                }

                <SfNumericTextBox @bind-Value="item.Gia" Min="@min" @onchange="()=>UpdateGridBanHangSum()"></SfNumericTextBox>

            </Template>

        </GridColumn>


        <GridColumn HeaderText="Order" TextAlign="TextAlign.Center" Width="100">

            <Template>

                <button @onclick="() => HandleOrderButtonClick(context as SanPhamModel)">Order</button>

            </Template>

        </GridColumn>

        <GridColumn HeaderText="Delete" TextAlign="TextAlign.Center" Width="100">

            <Template>

                <button @onclick="() => HandleDeleteButtonClick(context as SanPhamModel)">Delete</button>

            </Template>

        </GridColumn>

    </GridColumns>


</SfGrid>


private void UpdateGridBanHangSum()

{

    totalGia = gridBanHang.Sum(p => p.Gia);

    totalGiaWithCondition = CalculateSumWithCondition();

}

The problem is  The "totalgia" only updates when lose focus, Is there a way to make it update immediately as the user inputs a number into any cell of the SfNumericTextBox? Thank you


3 Replies

PS Prathap Senthil Syncfusion Team May 23, 2024 01:38 PM UTC

Hi Nguyen,

Based on your problem, we would like to inform you that we have prevented unwanted rendering of the Grid component during external actions for better performance. Therefore, we suggest you use PreventRender(false) on the
UpdateGridBanHangSum method to reflect the changes and achieve your requirement. Kindly refer to the attached code snippet for your reference.

private void UpdateGridBanHangSum()

{

    totalGia = gridBanHang.Sum(p => p.Gia);

    totalGiaWithCondition = CalculateSumWithCondition();

         Grid.PreventRender(false);

 

 

}

 

 


Regards,
Prathap Senthil



NT Nguyen Tom replied to Prathap Senthil May 23, 2024 10:11 PM UTC

Hi,
Thanks  Prathap Senthil, I tried adding the code you provided, however, it still doesn't work as expected. I still have to hit enter or tab or lose focus for the total price to change.How to change in real-time.

<SfGrid DataSource="@gridBanHang" @ref="grdBanHang">

    <GridEditSettings Mode="EditMode.Batch"></GridEditSettings>

    <GridColumns>

        <GridColumn Field=@nameof(BanHangModel.Id) HeaderText="ID" AllowEditing="false" TextAlign="TextAlign.Right" Visible="false"></GridColumn>

        <GridColumn Field=@nameof(BanHangModel.TenSanPham) HeaderText="Tên Sản Phẩm" AllowEditing="false"></GridColumn>

        <GridColumn Field=@nameof(BanHangModel.Gia) HeaderText="Giá" Format="N2">

            <Template>

                @{


                    var item = context as BanHangModel;

                    double min;

                    if (item.Id == 399 || item.Id == 398)

                    { min = double.MinValue; }

                    else

                    { min = 0; }

                }

                <SfNumericTextBox @bind-Value="item.Gia" ShowSpinButton="false" Min="@min" @onchange="()=>UpdateGridBanHangSum()"></SfNumericTextBox>

            </Template>

        </GridColumn>

        <GridColumn Field=@nameof(BanHangModel.SL) HeaderText="Sl">

            <Template>

                <SfNumericTextBox Min="1" Format="N0" ShowSpinButton="false"></SfNumericTextBox>

            </Template>

        </GridColumn>

        <GridColumn Field=@nameof(BanHangModel.SLCL) HeaderText="Sl Có" Format="N2"></GridColumn>

        <GridColumn HeaderText="Order" TextAlign="TextAlign.Center" Width="100">

            <Template>

                <button @onclick="() => HandleOrderButtonClick(context as BanHangModel)">Order</button>

            </Template>

        </GridColumn>

        <GridColumn HeaderText="Delete" TextAlign="TextAlign.Center" Width="100">

            <Template>

                <button @onclick="() => HandleDeleteButtonClick(context as BanHangModel)">Delete</button>

            </Template>

        </GridColumn>

    </GridColumns>

</SfGrid>

<div style="position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); display: flex; justify-content: space-between; width: 90%;">

    <SfButton style="width:45%" OnClick="@(e => OnZoomBtnClick())">Tiền mặt: @totalGia.ToString("N2")</SfButton>

</div>


@code {

private double totalGia = 0;

private SfGrid<BanHangModel> grdBanHang;

 private void UpdateGridBanHangSum()

 {

     grdBanHang.PreventRender(false);

     totalGia = gridBanHang.Sum(p => p.Gia);

 }

}



PS Prathap Senthil Syncfusion Team May 27, 2024 06:21 AM UTC

Before proceeding with the reporting of the problem, we require some additional clarification from your end. Please share the following details to proceed further on our end:

  • To analyze the reported issue, could you please share a simple and reproducible sample with duplicate data that demonstrates the problem? This will assist us in identifying the issue more efficiently and providing a resolution.

  • Could you please share us the video demonstration of the issue with replication steps?

  • Share with us a grid code snippet with the model class?

The details requested above will be very helpful in validating the reported query on our end and providing a solution as soon as possible. Thanks for your understanding.


Loader.
Up arrow icon