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

Checkbox uses changeEditor, but need to call other code

1 Answer 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeremy Yoder
Top achievements
Rank 1
Jeremy Yoder asked on 05 Apr 2016, 06:55 PM

 

Checkboxes in a batch grid require an extra click to put them into Edit mode, but that's fixed with this code I got on this forum...

function changeEditor(sender) {
    var grd = GetControlRAD("grdPODetails");
    var batchManager = grd.get_batchEditingManager();
    batchManager.openCellForEdit(sender.parentElement.parentElement);
    sender.checked = !sender.checked;
}

<telerik:RadGrid ID="grdPODetails" runat="server" AllowSorting="True" AutoGenerateColumns="False" Skin="Office2010Blue" GridLines="None">
    <HeaderContextMenu EnableAutoScroll="True">
    </HeaderContextMenu>
    <MasterTableView CommandItemDisplay="Top" EditMode="Batch" InsertItemDisplay="Bottom"
            ClientDataKeyNames="PurchaseOrderDetailKey"
            DataKeyNames="PurchaseOrderDetailKey">
        <BatchEditingSettings EditType="Cell" OpenEditingEvent="Click" />
        <CommandItemSettings ShowRefreshButton="False" ShowSaveChangesButton="true" ShowCancelChangesButton="true" />
        <NoRecordsTemplate>
            No detail lines to display.
        </NoRecordsTemplate>
        <Columns>
 
            <telerik:GridTemplateColumn DataField="PrintOnPurchaseOrder" HeaderText="Print" UniqueName="PrintOnPurchaseOrder" DataType="System.Boolean">
                <HeaderStyle Width="40px" />
                <ItemStyle Width="40px" />
                <ItemTemplate>
                    <input id="chkPrint" type="checkbox" checked='<%# Eval("PrintOnPurchaseOrder") %>' onclick="changeEditor(this);" />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:CheckBox ID="chkPrint" runat="server" Checked='<%# Bind("PrintOnPurchaseOrder") %>' />
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn DataField="PostToGeneralLedger" HeaderText="Post" UniqueName="PostToGeneralLedger" DataType="System.Boolean">
                <HeaderStyle Width="40px" />
                <ItemStyle Width="40px" />
                <ItemTemplate>
                    <input id="chkPost" type="checkbox" checked='<%# Eval("PostToGeneralLedger") %>' onclick="changeEditor(this);" />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:CheckBox ID="chkPost" runat="server" Checked='<%# Bind("PostToGeneralLedger") %>' />
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
 
            <telerik:GridTemplateColumn DataField="UnitDescription" UniqueName="UnitDescription" HeaderText="Unit Desc" DataType="System.String">
                <ItemTemplate>
                    <asp:Label ID="lblUnitDescription" runat="server"
                        Text='<%# Eval("UnitDescription") %>'>
                    </asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadTextBox ID="txtUnitDescription" runat="server" MaxLength="10" Width="100%"
                    Text='<%# Bind("UnitDescription") %>' >
                    </telerik:RadTextBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
 
        </Columns>
    </MasterTableView>
    <ClientSettings AllowKeyboardNavigation="true">
        <Selecting AllowRowSelect="True" />
        <ClientEvents/>
    </ClientSettings>
</telerik:RadGrid>

 

A breakpoint in changeEditor shows it's only called once, to put it in edit mode. But the first time you click it (and every time following if you keep clicking it while still in edit mode) I need to handle that event. For instance, in this grid, if I check the checkbox in the 2nd column, how can I set column "UnitDescription" in the same row to "A", but if I uncheck the checkbox (while still in EditMode) it sets UnitDescription" to "B"?

I tried putting an event handler on the checkbox within EditItemTemplate, but that didn't work... or I did it wrong. It's almost like when it opens in edit mode, a new checkbox is created on the fly. But I can't figure out where it is or how to grab its events. Please help.

 

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 08 Apr 2016, 01:31 PM
Hi Jeremy,

A possible solution is to update the cell value by calling changeCellValue method and pass the cell element and the new value. Please check out the following help article for more information. Additionally you can examine the following how to article for more details.

Regards,
Kostadin
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Jeremy Yoder
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or