Open ValentinTudorM opened 7 years ago
We have also a custom solution, but we cannot extend some framework private members. I can comeback with details
Hm... how about grid.addOpenListener((e) -> if (isBadBean(e.getBean())) { grid.getEditor().cancel(); }}
? I've used this workaround for a long long time now (extended Grid to have open/close events back in 7 when it didn't have them).
Not a solution but for provided example, would it be easier to just make the total row as a GridFooter
?
@pwilkin editor.addOpenListener
instead of grid.addOpenListener
.
Can you give instructions how to add close editor event?
Actually method mentioned by @pwilkin does not work with latest Vaadin versions, see https://github.com/vaadin/framework/issues/11002
There is a partial workaround in case un-buffered editor is used, one can use https://vaadin.com/directory/component/gridfastnavigation-add-on
Note: was initially open on grid section and tomivirkki recommend to open here, on framework section.
Vaadin version – Release 8.1
PROBLEM – there is no support to enable/disable row editor based on row data.
Depending of row (binded) data a row must be editable or not ~ row edit must be set as enabled disabled. Simple example: totals rows must not be editable. Problem is described for buffered mode. Unbuffered mode is worse. More – if the row problem it is solved, we have also no problems to setup cols/cells as editable: we can set editor components directly. Also we have solved this aspect: <<Prevent edit on non editable column #9844 - pull request>>
Grid intention – to set various properties based on current row object. Now it is inconsistent:
DETAILS - Why enable/disable row editor does not work? We cannot always retrieve the current row when we enter in editing. The grid use two types of selection:
The Grid offers an event for row selection change, that could be used to setup the properties for that row, but also for editing columns/cells
private void OnSelChangeRow(SelectionEvent e) {
if (e == null) return;
Set selected = e.getAllSelectedItems();
if (selected == null || selected.isEmpty()) { return; }
GridAssociatedObject bean = selected.iterator().next();
I do not want that total rows to be editable in any way – the editor will be disabled if the row is total row and reverse The problem is that I could also navigate with the arrows keys and:
IMPORTANT: in this case I cannot set not editable/not editable rows based on row associated object
PROPOSALS - The API must be consistent in managing rows and cells properties. Example of possible behavior fixes:
EXAMPLE OF THE PROBLEM
In this grid, only the total row must be read-only. The associated row object have a isTotal property. The editor it is enabled/disable as f(isTotal) in row selection change listener (see above code and/or the attached example file at the end).
SCENARIO – select an editable row (we have change also the style – editable cells in yellow) – navigate with the arrow keys to the non-editable, total row and press Enter: the editor is set according to the selected row, not to the selected cell. So, we cannot setup the total row as read only
IMPORTANT
We can attach also full example code, but it is trivial.