Delete does not refresh the table

Hi,

I am using the grid to display some data.

I have the delete functionality, but when executing, the grid is not refreshed, meaning the row has not been removed on screen.

Here is how I do.

In the Razor Page
public JsonResult OnPostDelete([FromBody]ICRUDModel<MyData> value)
        {
            return new JsonResult(value);
        }

In the view .cshtml
List<object> toolbarItems = new List<object>();
toolbarItems.Add(new { text = "Search", align = "Left" });
toolbarItems.Add(new { text = "Delete", align = "Right" });
<ejs-grid id="Grid"
              load="onLoad"
              rowSelected="rowSelected"
              rowDataBound="rowBound"
              allowExcelExport="true"
              allowPaging="true"
              allowResizing="true"
              AllowTextWrap="true"
              allowSorting="true"
              allowFiltering="true"
              toolbarClick="toolbarClick"
              toolbar="@toolbarItems">

            <e-grid-editSettings allowEditing="true"
                                 allowDeleting="true"
                                 mode="Normal"
                                 showDeleteConfirmDialog="true"></e-grid-editSettings>
            <e-data-manager url="/?handler=DataSource"
                            updateUrl="/?handler=Update"
                            removeUrl="/?handler=Delete"
                            adaptor="UrlAdaptor"></e-data-manager>

<e-grid-columns>
<e-grid-column field="Id" isPrimaryKey="true" headerText="Id" textAlign="Center" width="120"></e-grid-column>
<e-grid-column field="Description" headerText="Description" width="200" allowEditing="false"></e-grid-column>
<e-grid-column field="Comment" headerText="Comments" validationRules="@(new {  maxLength=100})" width="150" template="#templateComment"></e-grid-column>
</e-grid-columns>
</ejs-grid>


The OnPostDelete method is being called, but the grid still displays the deleted row.

Please spot what I am doing wrong.

Thank you!

2 Replies

EL Elisabeth April 27, 2020 08:45 AM UTC

Hi,

It started working, when I put a server code to update the database.
Can you explain why please?

Thanks!



SK Sujith Kumar Rajkumar Syncfusion Team April 27, 2020 09:27 AM UTC

Hi Elisabeth, 
 
Greetings from Syncfusion support. 
 
On using URL Adaptor and deleting a record from the Grid two requests will be sent. One to remove the record from the underlying data(Delete request) and another to fetch the updated records(URL method). So while the request for the Delete method is sent, the data must be removed from the underlying data source/database so that next time request is sent to fetch the updated data the deleted record is removed from that. Please check below code snippet where the record is removed from the List data bound to the Grid and then deleted record value is returned back to the Grid, 
 
public IActionResult Delete([FromBody]ICRUDModel<OrdersDetails> value) 
        { 
            // Record is removed from the underlying data bound to the Grid 
            OrdersDetails.GetAllRecords().Remove(OrdersDetails.GetAllRecords().Where(or => or.OrderID == int.Parse(value.key.ToString())).FirstOrDefault()); 
            return Json(value); 
        } 
 
We have prepared a sample based on this for your reference. You can download it from the below link, 
 
 
 
Please get back to us if you require any further assistance. 
 
Regards, 
Sujith R 


Loader.
Up arrow icon