DataGrid InLine Editing doesn't work

Hi, I tried to use DataGrid InLine Editing w/o succes via the link https://github.com/radzenhq/radzen-blazor/blob/master/RadzenBlazorDemos/Pages/DataGridInLineEdit.razor

The code is

<RadzenButton ButtonStyle="ButtonStyle.Success" Icon="add_circle_outline" class="mt-2 mb-4" Text="Add New Order" Click="@InsertRow" Disabled=@(suiviBEToInsert != null || suiviBEToUpdate != null) />

<RadzenDataGrid @ref="grid" AllowAlternatingRows="false" AllowFiltering="true" AllowPaging="true" PageSize="5" AllowSorting="true" EditMode="DataGridEditMode.Single"
            Data="@developers" TItem="SuiviBE" RowUpdate="@OnUpdateRow" RowCreate="@OnCreateRow" Sort="@Reset" Page="@Reset" Filter="@Reset" ColumnWidth="200px">
    <Columns>

...
RadzenDataGrid<SuiviBE>? grid;
    SuiviBE dev = new SuiviBE();
    // IList<SuiviBE> developers;
    SuiviBE[]? developers { get; set; }
       
    SuiviBE suiviBEToInsert;
    SuiviBE suiviBEToUpdate;

   protected override async Task OnInitializedAsync()
   {
       developers = await client.GetFromJsonAsync<SuiviBE[]>("api/etude");
         
   }
    void Reset()
    {
        suiviBEToInsert = null;
        suiviBEToUpdate = null;
    }

    async Task OnCreateRow()
    {
        await client.PostAsJsonAsync("api/etude", dev);        
        uriHelper.NavigateTo("etude");
    }

     async Task OnUpdateRow()
    {
        await client.PutAsJsonAsync("api/etude", dev);        
        uriHelper.NavigateTo("etude");
    }

    async Task EditRow(SuiviBE suivi)
    {
        suiviBEToUpdate = suivi;
        await grid.EditRow(suivi);
    }

   async Task InsertRow()
   {
       suiviBEToInsert = new SuiviBE();
       await grid.InsertRow(suiviBEToInsert);
   }

      async Task SaveRow(SuiviBE suivi)
    {
        await grid.UpdateRow(suivi);
    }

OnCreate call the the method HttPost

  [HttpPost]
        public async Task<IActionResult> Post(SuiviBE developer)
        {
            _context.Add(developer);
            await _context.SaveChangesAsync();
            return Ok(developer.Id);
        }

With this code is not possible to modified the the line. Do you see where I've made a mistake?

Thnaks in advance to your support

The same code works normally runtime:

thanks to your reply.
So, I would like to know the method I can create EditRow and InsertRow ... direcly in my controller??

I've put the information below in definition of the radzendatagrid

<RadzenDataGrid ...........Data="@developers" TItem="SuiviBE" RowUpdate="@OnUpdateRow" RowCreate="@OnCreateRow" .../>

@code 
{
RadzenDataGrid<SuiviBE>? grid;
 SuiviBE[]? developers { get; set; }

protected override async Task OnInitializedAsync()
    {
        developers = await client.GetFromJsonAsync<SuiviBE[]>("api/etude");

    }

    async Task OnCreateRow()
    {
        await client.PostAsJsonAsync("api/etude", dev);        
        uriHelper.NavigateTo("etude");
        suiviBEToInsert = null;
    }

  async Task OnUpdateRow()
    {
        await client.PutAsJsonAsync("api/etude", dev);        
        uriHelper.NavigateTo("etude");
        suiviBEToUpdate = null;

    }

}

the controller is definied as below :

[Route("api/[controller]")]
    [ApiController]
    public class EtudeController : ControllerBase
    {

        private readonly ApplicationDbContext _context;
        public EtudeController(ApplicationDbContext context)
        {
            this._context = context;
        }
[HttpGet]
        public async Task<IActionResult> Get()
        {
            var devs = await _context.SuiviBEs.ToListAsync();
            return Ok(devs);
        }

[HttpPost]
        public async Task<IActionResult> Post(SuiviBE developer)
        {
            _context.Add(developer);
            await _context.SaveChangesAsync();
            return Ok(developer.Id);
        }

        [HttpPut]
        public async Task<IActionResult> Put(SuiviBE developer)
        {
            _context.Entry(developer).State = EntityState.Modified;
            await _context.SaveChangesAsync();
            return NoContent();
        }

I don't understand why the HttpPost and HttpGet doesn't work. Have you an idea?
The HttpGet work perfectly!

thanks in advance to your support!

We have no idea what "does not work" mean in this context. What happens when you debug the application? Are the action methods hit? Do you see any requests made from the browser's developer tools?

Are the action methods hit?

Yes I've put the break point eg @OnCreate and the method is hit.

In text box in datagrid (metier in my example) I added the text "toto"
I see that when the method is actived the field metier is not fill =null

hould I define my methods differently? but it seems correct?
Can RowCreate in datagrid work like this?

In our demo the new and updated records are passed as event arguments:

void OnUpdateRow(Order order)
{
}

   void OnCreateRow(Order order)
    {
        dbContext.Add(order);

        dbContext.SaveChanges();
        
        orderToInsert = null;
    }

The code you have pasted doesn't seem to do that - it uses something called dev and definitely isn't the argument provided to the event handlers.

I recommend checking our online demo and comparing it to your implementation.

you right I've to to put developers instead of dev
but it doesn't anything.

I've checked your demo
RowCreate="@OnCreateRow" is associated to

 void OnCreateRow(Order order)
    {
        dbContext.Add(order);

        dbContext.SaveChanges();
        
        orderToInsert = null;
    }

in my code RowCreate="@OnCreateRow" is associated to

  async Task OnCreateRow()
    {
        await client.PostAsJsonAsync("api/etude", dev);        
        uriHelper.NavigateTo("etude");
        suiviBEToInsert = null;
    }

that call the method

 [HttpPost]
        public async Task<IActionResult> Post(SuiviBE developer)
        {
            _context.Add(developer);
            await _context.SaveChangesAsync();
            return Ok(developer.Id);
        }

It's seem to be the same thing. I don't understand why the row is not populate when I used my code?

Because you are not using the parameter of the RowCreate event which is the new item. It should be something like this:

    async Task OnCreateRow(SuiviBE newRow) 
    {
        await client.PostAsJsonAsync("api/etude", newRow);        
        uriHelper.NavigateTo("etude");
        suiviBEToInsert = null;
    }
1 Like

Super! thank you very much it's work perfectly!!