We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Grid with ObservableCollection?

Hello ;)

I want to use the Grid in a server side application  to edit a few values which needs processing after editing.
So I need an event when the user changed something in the List.
My idea was to use an ObservableCollection to implement this.

For adding a new value this works fine, but it looks like editing and removing is not working.
I'm getting an error in the browser console when I turn detailed error reporing on.

I assume, that I can use any IEnumerable as a DataSource?

(I can not paste the code here after an edit - some parts are missing...)



regards Manuel





3 Replies

VN Vignesh Natarajan Syncfusion Team September 16, 2019 06:26 AM UTC

Hi Manuel,  

Thanks for contacting Syncfusion support.  

Query: “For adding a new value this works fine, but it looks like editing and removing is not working. 
                                                      
We have prepared a sample using your code example and we are able to reproduce the reported issue at our end too. The root cause of an issue is while performing CRUD (Add, Edit, Delete etc ) action, it is necessary to define the IsPrimaryKey property to any of the available Grid columns. (i.e) one column must be PrimaryKey column whose value must be unique. Based on primaryKey value only, inserting, editing, deleting operation will take place. Refer our UG documentation for your reference 


Refer the below cod example for your reference 

<EjsGrid DataSource="@ObsOrders"  AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete" })"> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
…………………… 
</EjsGrid> 
 

Please get back to us if you have further queries.  

Regards,
Vignesh Natarajan. 



MR Manuel Reinacher September 16, 2019 11:30 AM UTC

Hello Vignesh Natarajan,

Thanks for your help.

Adding and removing is now working fine.
When I edit a value I don't get any CollectionChanged event on the list.

- This would be very useful, because then you could use these events to handle the changes from the grid.

regards Manuel




VN Vignesh Natarajan Syncfusion Team September 17, 2019 10:07 AM UTC

Hi Manuel, 

Thanks for the update.   

We are glad to hear that your query has been resolved.  

Query: “When I edit a value I don't get any CollectionChanged event on the list. 
 
CollectionChanged method itself will be triggered only when entire list is changed, removed or added. So it will not be triggered when one of the individual member is changed. Refer the below stackoverflow link for your reference. 


Same requirement (use these events to handle the changes from the grid) can be achieved using OnActionComplete event of EjsGrid. This event will be triggered whenever certain actions are completed in Grid. In the event arguments you can get the modified data and request type.  

Refer the below code example  

<EjsGrid DataSource="@ObsOrders"  AllowPaging="true"  Toolbar="@(new List<string>() { "Add", "Edit", "Delete" })"> 
    <GridEvents OnActionComplete="OnComplete" TValue="Order"></GridEvents> 
    .          .            .         .        .     .  
</EjsGrid> 
.          .            .        .         .  
  public void OnComplete(ActionEventArgs<Order> Args) 
    { 
        if(Args.RequestType.ToString() == "Save") 
        { 
 
        } 
    } 
  
Also refer our UG documentation for the list of available events 


Please get back to us if you have further queries.   

Regards, 
Vignesh Natarajan. 


Loader.
Live Chat Icon For mobile
Up arrow icon