Reset Datagrid Cell Focus in code behind

Is there a way to reset which Cell the datagrid is focused on in code? The issue is when editing the datagrid inline, the cell that is edited when calling the method datagrid.editItem() will be that same column on a new row (we have a button that create a new record in the grid in which the focus changes to that row)

for example if I edit the 3rd column and save the changes, when I click the create button, the newly created row will have the focus on the 3rd column for that row.

what I want to accomplish is that the focus is on the first field on the far left every time I click create record.

Thanks.

1 Like

Hi,

Unfortunately, there is no ability to control the focus programmatically. But, for your case, I can suggest a workaround. Set EditorFieldGenerator for the first field and call requestFocus() before return the generated field, e.g.


@Override
public void init(Map<String, Object> params) {
	customersDataGrid.getColumnNN("name")
			.setEditorFieldGenerator((datasource, property) -> {
				TextField nameField = componentsFactory.createComponent(TextField.class);
				nameField.setDatasource(datasource, property);
				nameField.requestFocus();
				return nameField;
			});
}

Regards,
Gleb

Thanks Gleb, That did the trick however it suffers weird behaviour. It still remembers the last position of the selected cell, so when hitting Tab to shift to the next cell, it jumps to the column last selected from a previous edit. Anyway to reset this as well?

Thanks,
Darian.

Iā€™m in a similar situation right now - is there a new way of doing this with CUBA 7.2?

Tell me how to reset selected cell position? This should fix the problem, thx.