syncfusion / flutter-widgets

Syncfusion Flutter widgets libraries include high quality UI widgets and file-format packages to help you create rich, high-quality applications for iOS, Android, and web from a single code base.
1.57k stars 771 forks source link

Start editing when coming from another control #2031

Closed JuanLuisNL closed 1 month ago

JuanLuisNL commented 2 months ago

Use case

In a Windows form I want to be able to start editing the grid when coming from another control by pressing TAB or ENTER.

Proposal

image I would like an event that is triggered when the grid receives the focus via keyboard. We used to work in NET and we are used to use grids like this, maybe there is a way to do it, but I have tried many things and I have not been able to do it.

abineshPalanisamy commented 2 months ago

Hi @JuanLuisNL ,

You can modify the Tab or Enter key behavior by using the handleKeyEvent method within the RowSelectionManager. Inside handleKeyEvent(), check if the Tab or Enter key is pressed. Based on the current cell's rowColumnIndex, you can then initiate cell editing. Additionally, wrap the DataGrid in a Focus widget. When the focus is removed from the DataGrid, clear the selection to ensure the DataGrid loses focus.

We have included a sample for your reference. Please review this sample for more details and adapt it to suit your specific requirements.

Regards, Abinesh P

JuanLuisNL commented 2 months ago

Thank you very much for your quick response. I am doing everything you have told me. In your code when I write this, it works: focusText.addListener(() { if (!focusText.hasFocus) { WidgetsBinding.instance.addPostFrameCallback((_) async { await controller.beginEdit(RowColumnIndex(0, 1)); }); } }); Exiting the control with TAB puts the grid into edit mode.

In my code it doesn't work if I press TAB. However, it does work if, for example, from a button or from the ‘change’ of the TextEdit I call :
await controller.beginEdit(RowColumnIndex(0, 1));

I will continue investigating, I know it is a problem of my code. Thank you very much. Regards, Juan Luis Marcos

JuanLuisNL commented 2 months ago

He visto que cuando llamo a "beginEdit" desde el cambio de foco, en la siguien funcion, dataGridConfiguration.columns._actualWidth es igual NaN (width = 30), por eso no encuentra ninguna columna. Sin embargo si hago click en la celda o llamo a "beginEdit" desde un boton, tiene el valor correcto:

image

abineshPalanisamy commented 2 months ago

Hi @JuanLuisNL ,

We are unclear about the issue based on the information provided. To assist you further and gain a better understanding of the problem, we kindly request additional details or steps related to calling beginEdit and reproducing the unexpected behavior. Please modify the previously attached sample to demonstrate the issue and provide a video recording that shows the problem for greater clarity. This will significantly aid us in investigating the issue and offering a prompt and appropriate solution.

Regards, Abinesh P

JuanLuisNL commented 1 month ago

Hello First of all, thank you for your attention. The conclusion I have come to is that in the example you have provided it works because the widget is painted twice. The first time ‘dataGridConfiguration.columns._actualWidth’ is equal to NaN , the second time it already acquires the value of ‘width’, so the function getLastCellIndex can return a value and ‘beginEdit’ can continue. beginEdit > dataGridConfiguration.currentCell.onCellBeginEdit > getLastCellIndex (this function returns and does not continue if _actualWidth in NaN)

Sorry for not explaining well, I don't know how to reproduce it in a simple example, as I have my custom widgets with a lot of code.

I'll keep investigating.

Thanks for your help!

JuanLuisNL commented 1 month ago

Hello I found the problem, I had the ‘SfDataGrid’ inside a ‘container’ with the property ‘key: UniqueKey()’, that caused an ‘unmount’ of SfDataGrid, and then :

void resetColumnProperties(DataGridConfiguration dataGridConfiguration) { for (final GridColumn column in dataGridConfiguration.columns) { column._filterFrom = FilteredFrom.none; column._actualWidth = double.nan; } }

Thanks for your help and sorry for the inconvenience!

Translated with DeepL.com (free version)

abineshPalanisamy commented 1 month ago

Hi @JuanLuisNL ,

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.

Regards, Abinesh P

JuanLuisNL commented 1 month ago

Thank you very much!