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

using OnValueChanging to clear other columns in insert mode

2 Answers 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Garrett
Top achievements
Rank 1
Garrett asked on 11 Jun 2014, 07:55 PM
Hi there,

I have a radgrid with 2 values, Amount1 and Amount2. If someone puts an amount in Amount1, I want the grid to automatically clear Amount2 so that only one of the two fields can be entered.

I have this almost working. If there is a single row in the grid and I am in EDIT MODE, it works. If I am in INSERT mode it does not work (is it because when you're in insert mode, the row you're adding isn't yet a row?) and if there is more than one row in the grid and I am editing a row, it tries to clear ALL rows, not just the one I'm editing, because of the row loop.

My question is 2 parts, one - how do I get the row ID of the row I'm editing and second how do I clear a control that is in INSERT mode?

 
<script type='text/javascript'>
    var run = false;
 
    function ClearOtherField(fieldname) {
        var grid = $find("<%=RadGrid2.ClientID %>");
            if (run == false) {
                run = true;
                if (grid) {
                    var MasterTable = grid.get_masterTableView();
                    var Rows = MasterTable.get_dataItems();
                    for (var i = 0; i < Rows.length; i++) {
                        var row = Rows[i];
 
                        var PercentageRadNumericTextBox = row.findControl(fieldname);
                        PercentageRadNumericTextBox.set_value("");
                    }
                }
                run = false;
            }
        }
        function AmountRadNumericTextBox_OnValueChanging() {
            ClearOtherField("PercentageRadNumericTextBox");
        }
 
        function PercentageRadNumericTextBox_OnValueChanging() {
            ClearOtherField("AmountRadNumericTextBox");
        }
 
 
</script>

2 Answers, 1 is accepted

Sort by
0
Garrett
Top achievements
Rank 1
answered on 11 Jun 2014, 08:03 PM
I found something similar instead of the row loop but I think since the row[0] is still defined, if I try to edit the second or later rows it breaks because it wants to edit the very first row:

<script type='text/javascript'>
    var run = false;
 
    function ClearOtherField(fieldname) {
        var grid = $find("<%=RadGrid2.ClientID %>");
            if (run == false) {
                run = true;
                if (grid) {
                    var PercentageRadNumericTextBox = grid.get_masterTableView().get_dataItems()[0].findControl(fieldname);
                        PercentageRadNumericTextBox.set_value("");
                }
                run = false;
            }
        }
        function AmountRadNumericTextBox_OnValueChanging() {
            ClearOtherField("PercentageRadNumericTextBox");
        }
 
        function PercentageRadNumericTextBox_OnValueChanging() {
            ClearOtherField("AmountRadNumericTextBox");
        }
 
 
</script>
0
Accepted
Eyup
Telerik team
answered on 16 Jun 2014, 01:02 PM
Hi Garrett,

You can use the approach suggested in the following post to achieve the requested functionality:
http://www.telerik.com/forums/passing-arguments-to-client-events#QkAxV87iOUalEx4wNaumeA

And within the JS function you can access the corresponding grid item and execute your custom logic:
Copy Code
Copy Code
var tableView = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
var item = tableView.get_dataItems()[index];

In addition, I am sending a sample RadGrid web site to demonstrate a similar implementation.

Hope this helps.


Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Garrett
Top achievements
Rank 1
Answers by
Garrett
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or