Enable/Disable grid editing at runtime

Hi,

I'm trying to enable editing in a sfGrid where editing initally is disabled. ( see my code below)
When the page is displayed the "Edit" button in the toolbar still is disabled ...

What am I doing wrong here ?

<SfGrid  @ref="DefaultGrid" DataSource="@Users" AllowSorting="true" AllowFiltering="true" Height="600" Toolbar="@(new List<string>() { "Edit"})">
        <GridEditSettings AllowEditing="false" Mode="EditMode.Dialog">
        </GridEditSettings>
        <GridColumns>
             . . .
        </GridColumns>       
</SfGrid>
@code {
    public List<UserModel> Users { get; private set; }
    private SfGrid<UserModel> DefaultGrid;

    protected override async Task OnInitializedAsync()
    {
        try
        {
            Users = await userService.ReadUsersAsync();
            ....   
        }
        catch (Exception ex)
        {
            Users = new List<UserModel>();
           ...
        }
    }
    public void Load(object args)
    {
        #pragma warning disable BL0005
        (this.DefaultGrid.EditSettings as GridEditSettings).AllowEditing = true;
        #pragma warning restore BL0005
    }
}

Thanks
Raivo


4 Replies 1 reply marked as answer

RA RaivoL May 5, 2021 12:32 PM UTC

My markup is like this:

<SfGrid  @ref="DefaultGrid" DataSource="@Users" AllowSorting="true" AllowFiltering="true" Height="600" Toolbar="@(new List<string>() { "Edit"})">
<GridEditSettings AllowEditing="false" Mode="EditMode.Dialog">
        </GridEditSettings>
        <GridColumns>
             . . .
        </GridColumns>  
<GridEvents OnLoad="Load" TValue="UserModel"></GridEvents>     
</SfGrid>


VN Vignesh Natarajan Syncfusion Team May 6, 2021 03:26 AM UTC

Hi Raivo,  
 
Thanks for contacting Syncfusion support.  
 
Query: “I'm trying to enable editing in a sfGrid where editing initally is disabled. ( see my code below) 
 
We have analyzed your query and we suggest you to achieve your requirement by using property binding for AllowEditing property of GridEditSettings instead of modifying in the Grid instance (ref) . Refer the below code example.  
 
@using Syncfusion.Blazor.Grids 
@using Syncfusion.Blazor.Buttons 
  
<SfButton Content="Enable/Disable" OnClick="Clicked"></SfButton> 
  
<SfGrid DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Edit""Cancel""Update" })"> 
    <GridEditSettings AllowEditing="CanEdit"></GridEditSettings> 
    <GridEvents OnLoad="Load" TValue="Order"></GridEvents> 
    . . . . . . 
</SfGrid> 
  
@code{ 
    public List<Order> Orders { getset; } 
  
    public bool CanEdit { getset; } 
  
    public void Clicked() 
    { 
        CanEdit = !CanEdit; 
    } 
  
    public void Load() 
    { 
        CanEdit = true; 
    } 
 
 
For your convenience we have attached the sample which can be downloaded from below 
 
 
Please get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan  


Marked as answer

RA RaivoL May 6, 2021 05:39 AM UTC

Great, that fixed it.
Thx for excellent support.

Regards,
Raivo


VN Vignesh Natarajan Syncfusion Team May 7, 2021 03:25 AM UTC

Hi Raivo,  

Thanks for the update.  

We are glad to hear that you have achieved your requirement using our solution.  

Please get back to us if you have further queries.  

Regards, 
Vignesh Natarajan 



Loader.
Up arrow icon