How to check duplicate record in edit mode

I have an sfgrid control.I am adding record in sfgrid from external control model using AddRecordasync methods.Before Adding row in sfgrid I am checking duplicate record using linq.It works fine but I would like to know how to check to duplicate record in Editmode before updating record.


For example

scenario 1:-

There is a record

First row : black

Second row :brown

If I change value from black to brown in edit mode,then it should say "brown" already exist,


Scenario 2:-

There is a arecord

First row First column : black

First row second column: 14

Second row First column : brown

Second row second column: 10


If I change second row second column value,then it should not check duplicate record.


Note:-

I am adding /updating record in grid from external control model.






1 Reply

RS Renjith Singh Rajendran Syncfusion Team January 18, 2022 03:10 PM UTC

Hi KINS,  

Greetings from Syncfusion support. 

Query : I would like to know how to check to duplicate record in Editmode before updating record. 
Based on your sceanrio, we suggest you to check for the availability of value(for example “Black”) in Grid’s DataSource. Based on the condition as whether its available or not you can call the UpdateRowAsync to programmatically update the row data. Please refer and use as like the codes below, 
 
 
<SfButton OnClick="OnClick">UpdateData</SfButton> 
 
    <SfGrid @ref="Grid" DataSource="@Orders" ...> 
        <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Normal"></GridEditSettings> 
        ... 
   </SfGrid> 
 
    @code{ 
    public string DuplicateMessage; 
    public async Task OnClick() 
    { 
        Order data = new Order() { OrderID = 1001, FirstColumn = "Black", SecondColumn = 4 }; 
        int IsCallUpdate = Orders.Where(e=> e.FirstColumn == data.FirstColumn).Count(); 
        if (IsCallUpdate == 0) 
        { 
            await this.Grid.UpdateRowAsync(1, data); 
            DuplicateMessage = "Updated Data"; 
        } 
        else 
        { 
            DuplicateMessage = "Duplicate value exists"; 
        } 
    } 
 
 
We are also attaching the sample for your convenience, please download the sample from the link below, 
 
Kindly try the above suggestion from your side and if we have misunderstood your requirement, kindly share the following details to validate the reported query further at our end.  
 
  1. Share the Grid code example of you current implementation.
  2. Share the complete codes regarding how you are performing updates in grid.
  3. Share with us a video demo showing the detailed explanation of your complete scenario and requirement.
 
The provided information will help us analyze the problem, and provide you a solution as early as possible. 
 
Regards, 
Renjith R 


Loader.
Up arrow icon