I've been following the example attached by Angel and have run into three issues with the code below.
1) Decimal values in Fee are ignored. So a 4.08 fee x 1 UnitsSold = 4.00 SoldFee
2) Values greater than 999 in UnitsSold are formatted with a comma and calculations result in a NaN.
3) The calculated WeightSold column can be overriden by the user and so is editable. When the javascript populates the column the numeric textbox disappears.
<script type=
"text/javascript"
>
function
CellValueChanged(sender,args) {
var
value = args.get_value();
var
columnName = args.get_columnUniqueName();
var
feeValue;
var
weightValue;
if
(columnName ==
"UnitsSold"
) {
feeValue = parseDouble(args.get_row().cells[2].innerText);
args.get_row().cells[5].innerText = (value * feeValue).toFixed(2);
weightValue = parseDouble(args.get_row().cells[3].innerText);
args.get_row().cells[6].innerText = value * weightValue;
}
}
function
parseDouble(value) {
if
(
typeof
value ==
"string"
) {
value = value.match(/^-?\d*/)[0];
}
return
!isNaN(parseInt(value)) ? value * 1 : NaN;
}
</script>
<
telerik:RadGrid
ID
=
"grdSalesReport"
runat
=
"server"
CellSpacing
=
"-1"
DataSourceID
=
"dsGrdSalesReport"
GridLines
=
"Both"
Visible
=
"False"
AllowAutomaticUpdates
=
"True"
>
<
GroupingSettings
CollapseAllTooltip
=
"Collapse all groups"
></
GroupingSettings
>
<
MasterTableView
AutoGenerateColumns
=
"False"
DataKeyNames
=
"ProducerReportDetailID"
DataSourceID
=
"dsGrdSalesReport"
EditMode
=
"Batch"
CommandItemDisplay
=
"Bottom"
>
<
CommandItemSettings
ShowAddNewRecordButton
=
"False"
ShowRefreshButton
=
"False"
/>
<
BatchEditingSettings
EditType
=
"Cell"
/>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"ShortDescription"
FilterControlAltText
=
"Filter ShortDescription column"
HeaderText
=
"Class"
SortExpression
=
"ShortDescription"
UniqueName
=
"ShortDescription"
ReadOnly
=
"True"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"LongDescription"
FilterControlAltText
=
"Filter LongDescription column"
HeaderText
=
"Description"
SortExpression
=
"LongDescription"
UniqueName
=
"LongDescription"
ReadOnly
=
"True"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Fee"
DataType
=
"System.Decimal"
FilterControlAltText
=
"Filter Fee column"
HeaderText
=
"Fee"
SortExpression
=
"Fee"
UniqueName
=
"Fee"
ReadOnly
=
"True"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"AvgWeight"
DataType
=
"System.Decimal"
FilterControlAltText
=
"Filter AvgWeight column"
HeaderText
=
"Average Weight"
SortExpression
=
"AvgWeight"
UniqueName
=
"AvgWeight"
ReadOnly
=
"True"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
DataField
=
"UnitsSold"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter UnitsSold column"
HeaderText
=
"Units Sold"
SortExpression
=
"UnitsSold"
UniqueName
=
"UnitsSold"
>
<
ItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"lblUnitsSold"
BorderStyle
=
"Solid"
BorderWidth
=
"2px"
BorderColor
=
"#007abb"
Width
=
"100px"
CssClass
=
"RightAlign"
Text='<%# Eval("UnitsSold", "{0}") %>'></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
span
>
<
telerik:RadNumericTextBox
RenderMode
=
"Lightweight"
Width
=
"100px"
runat
=
"server"
ID
=
"tbUnitsSold"
CssClass
=
"RightAlign"
MinValue
=
"0"
>
</
telerik:RadNumericTextBox
>
<
span
style
=
"color: Red"
>
<
asp:RequiredFieldValidator
ID
=
"RequiredFieldValidator1"
ControlToValidate
=
"tbUnitsSold"
ErrorMessage
=
"*Required"
runat
=
"server"
Display
=
"Dynamic"
>
</
asp:RequiredFieldValidator
>
</
span
>
</
span
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"SoldFee"
DataType
=
"System.Decimal"
FilterControlAltText
=
"Filter SoldFee column"
HeaderText
=
"Total Fee"
ReadOnly
=
"True"
SortExpression
=
"SoldFee"
UniqueName
=
"SoldFee"
>
<
ItemStyle
CssClass
=
"RightAlign"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
DataField
=
"WeightSold"
DataType
=
"System.Decimal"
FilterControlAltText
=
"Filter WeightSold column"
HeaderText
=
"Total Weight"
SortExpression
=
"WeightSold"
UniqueName
=
"WeightSold"
>
<
ItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"lblWeightSold"
BorderStyle
=
"Solid"
BorderWidth
=
"2px"
BorderColor
=
"#007abb"
Width
=
"100px"
CssClass
=
"RightAlign"
Text='<%# Eval("WeightSold", "{0}") %>'></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
span
>
<
telerik:RadNumericTextBox
RenderMode
=
"Lightweight"
Width
=
"100px"
runat
=
"server"
ID
=
"tbWeightSold"
CssClass
=
"RightAlign"
>
</
telerik:RadNumericTextBox
>
<
span
style
=
"color: Red"
>
<
asp:RequiredFieldValidator
ID
=
"RequiredFieldValidator2"
ControlToValidate
=
"tbWeightSold"
ErrorMessage
=
"*Required"
runat
=
"server"
Display
=
"Dynamic"
>
</
asp:RequiredFieldValidator
>
</
span
>
</
span
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"ProducerReportDetailID"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter ProducerReportDetailID column"
HeaderText
=
"ProducerReportDetailID"
ReadOnly
=
"True"
SortExpression
=
"ProducerReportDetailID"
UniqueName
=
"ProducerReportDetailID"
Display
=
"False"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
AllowKeyboardNavigation
=
"true"
>
<
ClientEvents
OnBatchEditSetCellValue
=
"CellValueChanged"
/>
</
ClientSettings
>
</
telerik:RadGrid
>