Wrong record in CurrentCellEndEdit

Hi,

I'm using following method to save data after editing cell in SfDataGrid:


public void CurrentCellEndEdit(CurrentCellEndEditEventArgs e)
{
if (e.OriginalSender is SfDataGrid grid && !grid.IsFilterRowIndex(e.RowColumnIndex.RowIndex))
{
var data = grid.View.GetRecordAt(grid.ResolveToRecordIndex(e.RowColumnIndex.RowIndex))?.Data;


        // save data
}
}


It works until grouping is used. Then I'm getting wrong record in data variable. Other I was editing.

Seems that record index is wrong. Isn't that a bug?


3 Replies

VS Vijayarasan Sivanandham Syncfusion Team December 21, 2021 01:19 PM UTC

Hi Ondrej Svoboda,

Your requirement to get record while grouping applied in SfDataGrid can be achieved by using SfDataGrid.View.TopLevelGroup.DisplayElements. Please refer the below code snippet,

 
private void OnCurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs e) 
{ 
            if (e.OriginalSender is SfDataGrid grid && !grid.IsFilterRowIndex(e.RowColumnIndex.RowIndex)) 
            { 
                object data = null; 
                 
                //get the record index 
                var recordIndex = grid.ResolveToRecordIndex(e.RowColumnIndex.RowIndex); 
 
                //Here check the Grouping applied or not in SfDataGrid 
                if (grid.View.TopLevelGroup != null) 
                { 
                    // Get the edited record while grouping applied in SfDataGrid 
                    var record = grid.View.TopLevelGroup.DisplayElements[recordIndex]; 
                    if (!record.IsRecords) //skips caption summary, group summary rows 
                        return; 
                    //get the record 
                    data = (record as RecordEntry).Data; 
                } 
                else 
                { 
                    // Get the edited record while grouping not applied in SfDataGrid 
                    data = grid.View.GetRecordAt(recordIndex)?.Data; 
                } 
 
                // save data 
            } 
} 

Sample Link: https://www.syncfusion.com/downloads/support/forum/171335/ze/SfDataGridDemo1123419523

Please let us know if you have any concerns in this. 

Regards, 
Vijayarasan S 



OS Ondrej Svoboda December 21, 2021 01:20 PM UTC

OK, thanks,



VS Vijayarasan Sivanandham Syncfusion Team December 22, 2021 03:16 AM UTC

Hi Ondrej Svoboda,

Thanks for the update.

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.

Regards,
Vijayarasan S

Loader.
Up arrow icon