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

Batch Edit - Set editor value based on another editor

3 Answers 231 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Yunuen Sanchez
Top achievements
Rank 1
Yunuen Sanchez asked on 08 May 2015, 01:16 AM
Hello, 
 
I would like to change the value of the editor numAmount based on the selected item in ddlCharge (client side). Using the event OnClientSelectedIndexChanged I can get the selected value but how can I update the numAmount value?
 

I tried something like this, but it doesn't affect the displayed value on the RadNumericTextBox

function SetDefaultAmountCombo(sender, eventArgs) {
    var selected = eventArgs.get_item().get_value();
    if (selected != null) {                                
        $telerik.findControl(document, "numAmount").set_value(40);
    }
}

 

Thanks

<telerik:RadGrid ID="gridOthers" runat="server" GridLines="None" AllowAutomaticDeletes="true" AllowAutomaticInserts="true" AllowAutomaticUpdates="true" DataSourceID="dsOthers"
                                            PageSize="10" AllowPaging="true" AutoGenerateColumns="false" OnBatchEditCommand="gridOthers_BatchEditCommand" ShowFooter="true" Width="700px" HorizontalAlign="Right"
                                            OnItemUpdated="gridOthers_ItemUpdated" OnItemInserted="gridOthers_ItemInserted" OnItemDeleted="gridOthers_ItemDeleted">
                                            <ClientSettings Resizing-AllowColumnResize="false">
                                                <ClientEvents />
                                            </ClientSettings>
                                            <MasterTableView CommandItemDisplay="Top" DataKeyNames="DriverSettlementDetailId" HorizontalAlign="NotSet" EditMode="Batch" DataSourceID="dsOthers"
                                                AutoGenerateColumns="false">
                                                <BatchEditingSettings EditType="Row" />
                                                <SortExpressions>
                                                    <telerik:GridSortExpression FieldName="ChargeDate" SortOrder="Ascending" />
                                                </SortExpressions>
                                                <Columns>
                                                    <telerik:GridBoundColumn DataField="DriverSettlementDetailId" ReadOnly="true" HeaderText="Id" UniqueName="DriverSettlementDetailId">
                                                        <HeaderStyle HorizontalAlign="Center" Width="50px" />
                                                        <ItemStyle HorizontalAlign="Center" />
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridTemplateColumn HeaderText="Type" UniqueName="ChargeId" DataField="ChargeId" DefaultInsertValue="Fuel">
                                                        <ItemTemplate>
                                                            <%# Eval("Charge.ChargeDesc") %>
                                                        </ItemTemplate>
                                                        <EditItemTemplate>
                                                            <telerik:RadComboBox runat="server" ID="ddlCharge" DataValueField="ChargeId" OnClientSelectedIndexChanged="SetDefaultAmountCombo"
                                                                DataTextField="ChargeDesc" DataSourceID="dsChargesOthers" Width="110px">
                                                            </telerik:RadComboBox>
                                                        </EditItemTemplate>
                                                        <HeaderStyle HorizontalAlign="Center" Width="150px" />
                                                        <ItemStyle HorizontalAlign="Center" />
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridBoundColumn DataField="Notes" HeaderText="Notes" SortExpression="Notes" ColumnEditorID="editorNotes"
                                                        UniqueName="Notes" FooterText="Total: ">
                                                        <HeaderStyle HorizontalAlign="Center" />
                                                        <ItemStyle HorizontalAlign="Left" />
                                                        <FooterStyle Font-Bold="true" HorizontalAlign="Right" />
                                                    </telerik:GridBoundColumn>
                                                    <telerik:GridTemplateColumn HeaderText="Amount" SortExpression="Amount" UniqueName="Amount"
                                                        DataField="Amount" FooterAggregateFormatString="{0:C2}" Aggregate="Sum">
                                                        <ItemTemplate>
                                                            <asp:Label runat="server" ID="lblAmount" Text='<%# Eval("Amount", "{0:C}") %>'></asp:Label>
                                                        </ItemTemplate>
                                                        <EditItemTemplate>
                                                            <span>
                                                                <telerik:RadNumericTextBox Width="95px" runat="server" ID="numAmount" Type="Currency">
                                                                </telerik:RadNumericTextBox>
                                                                <span style="color: Red">
                                                                    <asp:RequiredFieldValidator ID="rfvAmount"
                                                                        ControlToValidate="numAmount" ErrorMessage="*Required" runat="server" Display="Dynamic">
                                                                    </asp:RequiredFieldValidator>
                                                                </span>
                                                            </span>
                                                        </EditItemTemplate>
                                                        <HeaderStyle HorizontalAlign="Center" Width="100px" />
                                                        <ItemStyle HorizontalAlign="Right" />
                                                        <FooterStyle HorizontalAlign="Right" />
                                                    </telerik:GridTemplateColumn>
                                                    <telerik:GridButtonColumn ConfirmText="Delete this record?<br/><strong><i>Remember to click Save Changes before leaving the form</i></strong>" ConfirmDialogType="RadWindow"
                                                        ConfirmTitle="Delete" HeaderText="Delete" HeaderStyle-Width="50px" ButtonType="ImageButton"
                                                        CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                                                        <HeaderStyle HorizontalAlign="Center" />
                                                        <ItemStyle HorizontalAlign="Center" />
                                                    </telerik:GridButtonColumn>
                                                </Columns>
                                            </MasterTableView>

 

3 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 12 May 2015, 12:08 PM
Hello Yunuen,

I tried to replicate the issue, however, I was not able to. I am attaching a sample project I used for testing. The code from your post works as expected on my end. When another item in the RadComboBox is selected the value in the Amount field is changed.

Would you give the attached project a try and let me know if I am missing something? I will appreciate it if you could describe what should be changed in the sample in order to reproduce the issue.

Regards,
Viktor Tachev
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Yunuen Sanchez
Top achievements
Rank 1
answered on 12 May 2015, 05:39 PM

Hello Viktor,

The problem was related to the multiple grids I have on the page. Two of them were using the same RadNumericTexbox ID, I was getting a different reference.

 I was able to update the textbox, thanks!

Now I have another problem. OnClientSelectedIndexChanged event is firing multiple times during the row opening/editing/closing transactions. I found, on another thread, a way to dismiss these calls using the events: OnBatchEditClosing, OnBatchEditClosedOnBatchEditOpened and OnBatchEditOpening. But I'm still having one more issue: if I select a different item on the combobox and loose focus on the grid, an instant before the OnBatchEditClosing event is firing, the OnClientSelectedIndexChanged is fired with the combo having the original selected value prior edition, later OnClientSelectedIndexChanged is fired again now with the new selected value. Why is this happening?

0
Viktor Tachev
Telerik team
answered on 15 May 2015, 01:12 PM
Hi,

In order to implement the behavior you are looking for it is recommended to use the OnBatchEditClosed event. In its handler you can set the value for the amount cell via the RadGrid API.

The code snippet below illustrates the approach:


function batchEditClosed(sender, args) {
    var masterTableView = sender.get_masterTableView();
    var batchEditingManager = sender.get_batchEditingManager();
    var rowIndex = args.get_row().id.split("__")[1];
    var amountCell;
 
    if (args.get_column().get_uniqueName() == "ChargeId") {
        amountCell = masterTableView.getCellByColumnUniqueName(masterTableView.get_dataItems()[rowIndex], "Amount");
 
        setTimeout(function () {
            batchEditingManager.changeCellValue(amountCell, 40);
        }, 0);
    }
     
}



Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Yunuen Sanchez
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Yunuen Sanchez
Top achievements
Rank 1
Share this question
or