Hello,
I have this GridViewDataColumn "Real Quantity" which has a CellTemplate with a RadMaskedNumericInput,. If we put in a value (e.g. 0.02) and save it, it will fire an AggregateFunction which calculates the Qty remaining to 4.76. I tried to make this happen in real time while typing in a value without having to save and reload the page to show the calculation .
Does anyone have any idea how i could do this?
Regards,
Matthias
1 Answer, 1 is accepted
Hi Matthias,
The updates of the aggregate results happens on commit edit of the cell. There is no API that allows to easily achieve your requirement, but here is an idea that you can try. Basically, you can subscribe to the ValueChanged event of RadMaskedNumericInput and re-add the aggregate functions. For example:
private void RadMaskedNumericInput_ValueChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
var f = this.gridView.Columns[0].AggregateFunctions[0];
this.gridView.Columns[0].AggregateFunctions.Clear();
this.gridView.Columns[0].AggregateFunctions.Add(f);
}
I hope that helps.
Regards,
Martin Ivanov
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Hi Martin,
Thanks for the answer. i tried the code but it didn't change anything for my problem, the value inside the RadMaskedNumericInput still does not change.
Regards,
Matthias
I am not allowed to share my project. I can send you a code snippet:
xaml:
<telerik:GridViewDataColumn x:Name="lblRealQuantity" Header="Real Quantity" Width="110" Focusable="True" Tag="Translate">
<telerik:GridViewDataColumn.CellTemplate>
<DataTemplate>
<Grid>
<telerik:RadMaskedNumericInput x:Name="rmniChangedQuantity" Value="{Binding RealQuantity, Mode=TwoWay}" FormatString="N2" SelectionOnFocus="SelectAll" BorderThickness="0" ValueChanged="RadMaskedNumericInput_ValueChanged"/>
</Grid>
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
<telerik:GridViewDataColumn.AggregateFunctions>
<functions:RemainingQtyFunction ResultFormatString="{}{0:F}" />
</telerik:GridViewDataColumn.AggregateFunctions>
</telerik:GridViewDataColumn>
cs:
private void RadMaskedNumericInput_ValueChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
RadMaskedNumericInput radVal = sender as RadMaskedNumericInput;
DatabaseItem dbItem = radVal.DataContext as DatabaseItem;
if (radVal.Value != null)
dbItem.RealQuantity = Convert.ToDecimal(radVal.Value);
else
dbItem.RealQuantity = 0;
foreach (var column in grid.Columns)
if(column.AggregateFunctions[0] != null)
{
var f = column.AggregateFunctions[0];
column.AggregateFunctions.Clear();
column.AggregateFunctions.Add(f);
}
}
}
}
public class RemainingQtyFunction : AggregateFunction<DatabaseItem, string>
{
public RemainingQtyFunction()
{
this.AggregationExpression = items => RemainingQty(items);
}
private string RemainingQty(IEnumerable<DatabaseItem> source)
{
DatabaseItem firstItem = source.FirstOrDefault();
decimal totalQTY = firstItem.Quantity.Value * firstItem.OtherQuantity;
decimal remainingQTY = totalQTY - source.Sum(i => ((DatabaseItem)i).RealQuantity);
return string.Format("Qty remaining: {0} {1}", Math.Round(remainingQTY, 2), "kg");
}
}
I've tested the code and the aggregates are updated as expected. Can you try the attached project and let me know if I am missing anything?
Note that when you reset the aggregates the masked input control is losing the focus. I am afraid that there is proper way to avoid this.