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

Make cell readonly in row batch edit mode

1 Answer 442 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Madel
Top achievements
Rank 1
Madel asked on 19 Aug 2020, 10:05 AM

I am using a RadGrid with edit mode as batch and edit type is row. I have a GridCheckboxColumns in my grid which is editable when the row is selected.

When I select a row for editing, I want the checkbox cell to be readonly based on another cell value of the row. 

I have tried solutions from other posts such as cancelling edit on BatchEditOpening client-side event, making GridEditItem readonly on the server-side ItemCreated event and disabling checkbox on ItemDatabound event but none have worked for my scenario. 

Here is the sample code: I want PortalAccess checkbox cell to be readonly when 

    <telerik:RadGrid ID="grdContactsList" runat="server" AutoGenerateColumns="False" 
         OnBatchEditCommand="grdContactsList_BatchEditCommand"
        AllowSorting="true" EnableViewState="false" OnItemCommand="grdContactsList_ItemCommand" >
        <ClientSettings EnableRowHoverStyle="false" Selecting-AllowRowSelect="false" >
            <ClientEvents OnBatchEditOpening="batchEditOpening" />
        </ClientSettings>
        <MasterTableView TableLayout="Auto" CssClass="bordered" NoMasterRecordsText="No records to display." 
            AllowSorting="true" EditMode="Batch"
            <BatchEditingSettings EditType="Row" />
            <ColumnGroups>
                <telerik:GridColumnGroup HeaderText="Email Communications" Name="EmailCommunications"></telerik:GridColumnGroup>
            </ColumnGroups>
            <Columns> 
               <telerik:GridBoundColumn DataField="SponsorPortal" SortExpression="SponsorPortal" HeaderText="IsSponsor" UniqueName="IsSponsor"
                    Display="false" ReadOnly="true"></telerik:GridBoundColumn>   
              <telerik:GridCheckBoxColumn HeaderText="Portal Access" SortExpression="PortalAccess"
                    UniqueName="PortalAccess" DataField="PortalAccess"
                    HeaderStyle-CssClass="tblC" ItemStyle-CssClass="tblC">                                     
                </telerik:GridCheckBoxColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

 

1 Answer, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 24 Aug 2020, 08:05 AM

Hi Madel,

I am afraid that the desired behavior is not applicable together with the mentioned settings of the RadGrid as an out of the box solution.

Please check out the specifics of Batch Editing and see when it is suitable to use in the RadGrid Batch Editing Templates and Specifics KB article.

In short:

RadGrid is a server-side control and the Batch editing comes to provide a better performance and the convenience for making multiple changes which to be applied in a single request to the server.
On the other hand, dynamically turning on/off the read-only mode for a certain column, can only be achieved on the server-side, which is not applicable approach when it comes to Batch edit mode since postback to the server while editing the grid will cause loss of data.

Canceling the OnBatchEditOpening client-side event is a reliable way to prevent a cell from being edited if a certain condition is satisfied. Unfortunately, this approach is only usable when the EditType is set to Cell and cannot be used in the current case since the used EditType is Row.

Based on the circumstances above, here is what I would suggest achieving a behavior close to the desired one:

  • Use a server-side editing mode e.g the InPlace. It provides similar functionalities like the Batch editing in Row mode and you can use the server events to achieve the desired. 
  • Switch the EditType to Cell as that way canceling the OnBatchEditOpening event will work as expected and can be used to prevent editing the checkbox field.
  • In case you are focused on the client-side implementation, You may also consider using a complete client-side control like the Kendo Grid, see Batch editing.

I hope this will help you get a better overview and to find the most suitable solution for the current scenario. Please let me know if you have any further questions!

Kind regards,
Doncho
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Madel
Top achievements
Rank 1
Answers by
Doncho
Telerik team
Share this question
or