Disallow editing of field while inside inline editing

Hello,

Is it possible while inline editing to change the AllowEditing value of a field based on what is entered in another field? So after double clicking to enter inline editing on a grid all of my fields are editable. I would like to disable editing on some of them if a number > 0 is entered in one of the fields. This is while editing - not before entering editing.


Thanks



1 Reply

VN Vignesh Natarajan Syncfusion Team October 5, 2022 09:29 AM UTC

Hi Sheldon,


Thanks for contacting Syncfusion support.


Query: “ I would like to disable editing on some of them if a number > 0 is entered in one of the fields. This is while editing - not before entering editing.


As per your requirement we have prepared a sample to disable one column from editing based on another column value while editing. We have achieve this requirement using EditTemplate feature of Grid. Refer to the below code example.


<SfGrid @ref="GridInstance" AllowPaging="true" DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">

    <GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" Mode="@EditMode.Normal"></GridEditSettings>

    <GridColumns>

        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="@TextAlign.Center" Width="140"></GridColumn>

        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>

        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" EditType="EditType.NumericEdit" Format="C2" Width="140" TextAlign="@TextAlign.Right">

            <EditTemplate>

                <SfNumericTextBox TValue="double?" ID="Freight" @bind-Value="@((context as Order).Freight)" ShowClearButton="true">

                    <NumericTextBoxEvents TValue="double?" ValueChange="OnChange"></NumericTextBoxEvents>

                </SfNumericTextBox>

            </EditTemplate>

        </GridColumn>

        <GridColumn Field=@nameof(Order.OrderDate) HeaderText="Order Date" EditType="EditType.DatePickerEdit" Format="d" Type="ColumnType.Date" Width="160"></GridColumn>

        <GridColumn Field=@nameof(Order.ShipCountry) HeaderText="Ship Country" EditType="EditType.DropDownEdit" Width="150">

            <EditTemplate>

                <SfDropDownList ID="ShipCountry" Enabled="Enable" TItem="Country" TValue="string" @bind-Value="@((context as Order).ShipCountry)" DataSource="@Countries">

                    <DropDownListFieldSettings Value="CountryName" Text="CountryName"></DropDownListFieldSettings>

                </SfDropDownList>

            </EditTemplate>

        </GridColumn>

    </GridColumns>

</SfGrid>

 

 

@code {

    public SfGrid<Order> GridInstance{ get; set; }

    public bool Enable { get; set; } = true;

    public List<Order> Orders { get; set; }

    public void OnChange(Syncfusion.Blazor.Inputs.ChangeEventArgs<double?> Args)

    {

        if(Args.Value > 10){

            Enable = false;

        }

        else{

            Enable = true;

        }

        GridInstance.PreventRender(false);

    }


Kindly to refer the sample for your reference. Please get back to us if you have further queries.


Regards,

Vignesh Natarajan


Attachment: BlazorGrid_75b641c4.zip

Loader.
Up arrow icon