This is a migrated thread and some comments may be shown as answers.

RadNumericTextBox for Footer

3 Answers 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
myrad
Top achievements
Rank 1
myrad asked on 19 Nov 2010, 12:49 PM
Hi,

I am using your Grid / RadNumericTextBox for Footer Totals example.

<script type="text/javascript">
            var sumInput = null;
            var tempValue = 0.0;
            function Load(sender, args) {
                sumInput = sender;
            }
            function Blur(sender, args) {
                sumInput.set_value(tempValue + sender.get_value());
            }
            function Focus(sender, args) {
                tempValue = sumInput.get_value() - sender.get_value();
            } 
        </script>

I have got  2 columns,  Amount1 and Amount2.  

Amount1 is a GridBoundColumn and Amount2 is GridTemplateColumn which  have RadNumericTextBox. 

When I enter value in amount2 textbox it updates the textbox in footer control at client side using above JavaScript code, which is i great.

What I also want is this when user enter value in amount2  textbox i want to check if  this amount2 must be less than in Amount1 column at client side.

Can you please tell me how d i do this?

Many thanks



 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 22 Nov 2010, 08:17 AM
Mello Myrad,

The following code snippet  shows how to achieve this.

Java Script:
<script type="text/javascript">
  function Blur(sender, args) {
     var cell = sender.get_element().parentNode.parentNode;
     var index = cell.parentNode.rowIndex; // getting row index
     var grid = $find("<%=RadGrid1.ClientID %>");
     var MasterTable = grid.get_masterTableView();
     var row = MasterTable.get_dataItems()[index];
     var boundCol = MasterTable.getCellByColumnUniqueName(row, "Amount1").innerHTML; // accessing corresponding BoundColumn value using its ColumnUniqueName
     if (sender.get_value() < boundCol) //checking condition{
                }
   }
</script>

Thanks,
Princy.
0
myrad
Top achievements
Rank 1
answered on 22 Nov 2010, 12:14 PM
Hi Princy,

I have tried that code but at run time it thorws exception at this line (var boundCol = MasterTable.getCellByColumnUniqueName(row, "Amount").innerHTML;

'Microsoft JScript runtime error: 'undefined' is null or not an object'

Here is the javascript and .aspx code.

<telerik:RadScriptBlock runat="server" ID="RadScriptBlock1">

 

 

<

 

 

script type="text/javascript">

 

 

 

var sumInput = null;

 

 

 

var tempValue = 0.0;

 

 

 

function Load(sender, args) {

 

sumInput = sender;

}

 

 

function Blur(sender, args) {

 

 

 

var cell = sender.get_element().parentNode.parentNode;

 

 

 

var index = cell.parentNode.rowIndex; // getting row index

 

 

 

var grid = $find("<%=InvoicedAllocationGrid.ClientID %>");

 

 

 

var MasterTable = grid.get_masterTableView();

 

 

 

var row = MasterTable.get_dataItems()[index];

 

 

 

var boundCol = MasterTable.getCellByColumnUniqueName(row, "Amount").innerHTML; // accessing corresponding BoundColumn value using its ColumnUniqueName 

 

 

 

if (sender.get_value() < boundCol) {//checking condition{

 

 

 

// Do Nothing

 

}

 

 

else {

 

alert(

 

"Deducted amount must be less than original amount.");

 

}

}

 

 

 

function Focus(sender, args) {

 

tempValue = sumInput.get_value() - sender.get_value();

}

 

</

 

 

script>

 

 

 

</telerik:RadScriptBlock>


 

 

 

<telerik:RadGrid ID="InvoicedAllocationGrid" runat="server" AutoGenerateColumns="False"

 

 

 

 

 

 

 

GridLines="None" Skin="Vista" AllowMultiRowEdit="True" ShowFooter="True">

 

 

 

 

 

 

 

<MasterTableView DataKeyNames="Id" CommandItemDisplay="None">

 

 

 

 

 

 

 

<CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>

 

 

 

 

 

 

 

<Columns>

 

 

 

 

 

 

 

<telerik:GridBoundColumn DataField="info" HeaderText="Description" UniqueName="info" />

 

 

 

 

 

 

 

 

 

 

 

<telerik:GridBoundColumn DataField="Amount" UniqueName="Amount" HeaderText="Amount Invoiced" />

 

 

 

 

 

 

 

<telerik:GridTemplateColumn UniqueName="Template1" HeaderText="Amount to be Deducted">

 

 

 

 

 

 

 

<ItemTemplate>

 

 

 

 

 

 

 

<telerik:RadNumericTextBox runat="server" ID="txtAmount1" Type="Currency" Value="0">

 

 

 

 

 

 

 

<ClientEvents OnBlur="Blur" OnFocus="Focus" />

 

 

 

</telerik:RadNumericTextBox>

 

 

 

 

 

 

 

</ItemTemplate>

 

 

 

 

 

 

 

<FooterTemplate>

 

 

 

 

 

 

 

<telerik:RadNumericTextBox ID="txtAmount2" runat="server" Type="Currency" ReadOnly="true">

 

 

 

 

 

 

 

<ClientEvents OnLoad="Load" />

 

 

 

 

 

 

 

</telerik:RadNumericTextBox>

 

 

 

 

 

 

 

</FooterTemplate>

 

 

 

 

 

 

 

</telerik:GridTemplateColumn>

 

 

 

 

 

 

 

</Columns>

 

 

 

 

 

 

 

</MasterTableView>

 

 

 

 

 

 

 

</telerik:RadGrid>

 

 

 

 


Can you please help me to fix this proble?

Thanks

0
Princy
Top achievements
Rank 2
answered on 22 Nov 2010, 01:08 PM
Hello Myrad,

This error can occur because of getting wrong item index in client side. Please make appropriate modification in your code to get correct row index.

Java Script:
<script type="text/javascript">
  function Blur(sender, args) {
     var cell = sender.get_element().parentNode.parentNode;
     var index = cell.parentNode.rowIndex-1; //make appropriate modification here
     . . . . . . . . .
   }
</script>

Thanks,
Princy.
Tags
Grid
Asked by
myrad
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
myrad
Top achievements
Rank 1
Share this question
or