<EjsGrid DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" Height="315">
<GridEvents OnActionBegin="Begin" TValue="Order"></GridEvents>
. . . . . . . . . . .
<GridColumn Field=@nameof(Order.Credit) HeaderText="Credit" Format="C2" TextAlign="TextAlign.Right" Width="120">
<EditTemplate>
@{
var order = (context as Order);
<EjsNumericTextBox ID="Credit" TValue="int?" Value=@(GetValue(order,"Credit"))>
<NumericTextBoxEvents ValueChange="@((args)=>OnCreditChange(args,order))" TValue="int?"></NumericTextBoxEvents>
</EjsNumericTextBox>
}
</EditTemplate>
</GridColumn>
<GridColumn Field=@nameof(Order.Debit) HeaderText="Debit" Format="C2" TextAlign="TextAlign.Right" Width="120">
<EditTemplate>
@{
var order = (context as Order);
<EjsNumericTextBox ID="Debit" TValue="int?" Value=@(GetValue(order,"Debit"))>
<NumericTextBoxEvents ValueChange="@((args)=>OnDebitChange(args,order))" TValue="int?"></NumericTextBoxEvents>
</EjsNumericTextBox>
}
</EditTemplate>
</GridColumn>
</GridColumns>
</EjsGrid>
@code{
public int? GetValue(Order order, string columns)
{
if (columns == "Credit")
{
if (isEdit)
CreditScore = null;
return ((int?)(CreditScore ?? order.Credit));
}
else
{
if (isEdit)
DebitScore = null;
return ((int?)(DebitScore ?? order.Debit));
}
}
public bool CU = false;
public bool DU = false;
public bool isEdit = false;
public int? DebitScore { get; set; } = null;
public int? CreditScore { get; set; } = null;
public List<Order> Orders { get; set; }
public void Begin(ActionEventArgs<Order> Args)
{
if (Args.RequestType == Syncfusion.EJ2.Blazor.Grids.Action.BeginEdit)
{
isEdit = true;
}
}
public void OnCreditChange(Syncfusion.EJ2.Blazor.Inputs.ChangeEventArgs Args, Order Value)
{
isEdit = false;
if (!CU)
{
DebitScore = Value.principal - Convert.ToInt32(Args.Value);
DU = true;
}
else
{
CU = false;
}
}
public void OnDebitChange(Syncfusion.EJ2.Blazor.Inputs.ChangeEventArgs Args, Order Value)
{
isEdit = false;
if (!DU)
{
CreditScore = Value.principal - Convert.ToInt32(Args.Value);
CU = true;
}
else
{
DU = false;
}
}
}
|