Grid OnBatchEditOpening bug?

1 Answer 35 Views
Grid
Matthew
Top achievements
Rank 1
Iron
Iron
Matthew asked on 11 Sep 2024, 02:11 PM

I think I've found a bug in the Grid when in batch edit mode. I have created a following grid;


        <telerik:RadGrid ID="grdFees" runat="server" AutoGenerateColumns="False" GridLines="None"
            AllowSorting="False"  Height="310px"
            OnNeedDataSource="grdFees_NeedDataSource"
            OnPreRender="grdFees_PreRender" 
            OnItemDataBound="grdFees_ItemDataBound">
        <MasterTableView CellPadding="4" CommandItemDisplay="Top" EditMode="Batch" DataKeyNames="FeeTypeId, CurrencyCode, ShowCurrencyCode, Paid" ClientDataKeyNames="Paid,ShowCurrencyCode">
            <CommandItemSettings ShowExportToWordButton="false" ShowExportToExcelButton="false"
                ShowExportToCsvButton="false" ShowExportToPdfButton="false" ShowRefreshButton="false"
                ShowAddNewRecordButton="false" />
            <BatchEditingSettings EditType="Row" HighlightDeletedRows="true" OpenEditingEvent="Click" />
            <Columns>
                <telerik:GridBoundColumn UniqueName="Name" DataField="Name" HeaderStyle-Width="100px" ReadOnly="True" />

                <telerik:GridNumericColumn UniqueName="Amount" DataField="Amount" HeaderStyle-Width="70px" HeaderText="Amount" DecimalDigits="3"  />

                <telerik:GridTemplateColumn UniqueName="CurrencyCode" DataField="CurrencyCode" HeaderText="Currency Code" DefaultInsertValue="GBP" HeaderStyle-Width="60px">
                    <ItemTemplate>
                        <%# Eval("CurrencyCode") %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="CurrencyCodeDropDown" DataValueField="CurrencyCode"
                            DataTextField="CurrencyCode" MarkFirstMatch="true" AllowCustomText="true" >
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>

                <telerik:GridCheckBoxColumn UniqueName="Paid" DataField="Paid" HeaderStyle-Width="20px" HeaderText="Paid" SortExpression="Paid" ReadOnly="true" />

                <telerik:GridBoundColumn UniqueName="PaidDate" DataField="PaidDate" HeaderText="Paid Date" HeaderStyle-Width="100px" ReadOnly="True" 
                    DataFormatString="{0:yyyy-MM-dd HH:mm:ss}" />
            </Columns>
        </MasterTableView>
        <ClientSettings>
            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
            <ClientEvents OnBatchEditOpening="onBatchEditOpening" />
        </ClientSettings>
    </telerik:RadGrid>

with the javascript;


        function onBatchEditOpening(sender, args)
        {
            var row = args.get_row();
            var grid = $find("<%=grdFees.ClientID %>");
            var masterTable = grid.get_masterTableView();
            var rows = masterTable.get_dataItems();

            var isPaid = rows[row.sectionRowIndex].getDataKeyValue("Paid");

            if (isPaid === "True")
            {
                // prevent any editing on paid fees
                args.set_cancel("true");
                return;
            }

            var showCC = rows[row.sectionRowIndex].getDataKeyValue("ShowCurrencyCode");
            if (showCC === "False" && args.get_columnUniqueName() == "CurrencyCode")
            {
                // do not show Currency Code drop down menu
                args.set_cancel("true");
            }
   
        }

I want to prevent the RadComboBox from appearing if a value in the dataset is false. The good news is that it works. The bad news is after clicking on a row where showCC is false, the rest of the grid becomes unresponsive.

The grid comes back to life after clicking on Cancel Changes.

Is this a bug?

1 Answer, 1 is accepted

Sort by
0
Vasko
Telerik team
answered on 16 Sep 2024, 10:32 AM

Hi Matthew,

Thank you for the shared code snippet.

The Grid becomes unresponsive because the onBatchEditOpening method is being called 2 times, once for each cell that is about to go into edit mode. This is because the EditType for the cells is set to Row, and to fix that, you will need to set it to Cell:

<BatchEditingSettings EditType="Cell" HighlightDeletedRows="true" OpenEditingEvent="Click" />
function onBatchEditOpening(sender, args) {
    var row = args.get_row();
    var grid = $find("<%=grdFees.ClientID %>");
    var masterTable = grid.get_masterTableView();
    var rows = masterTable.get_dataItems();

    var isPaid = Boolean.parse(rows[row.sectionRowIndex].getDataKeyValue("Paid"))
    var showCC = Boolean.parse(rows[row.sectionRowIndex].getDataKeyValue("ShowCurrencyCode")); 

    // If Paid is true, cancel editing for the entire row
    if (isPaid === true) {
        args.set_cancel(true); 
    }

    // If ShowCurrencyCode is false and user tries to edit CurrencyCode column, cancel it
    if (showCC === false && args.get_columnUniqueName() === "CurrencyCode") {
        args.set_cancel(true);  // Prevent editing for CurrencyCode if ShowCurrencyCode is false
    }
}

Try adjusting the edit type and see if that will help you out.

Regards,
Vasko
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Iron
Iron
Answers by
Vasko
Telerik team
Share this question
or