I have a column in a ListGrid and I want this column to be frozen. I don't want users to be able to drag the header and resize this column's width.
I tried
column.setCanDragResize(false)
but had no luck.
Any suggestions?
First plz post code snippet or at least smart GWT version.
Second, that method works fine in this case:
ListGrid list = new ListGrid();
list.setWidth(500);
list.setHeight(300);
ListGridField listField = new ListGridField("first");
listField.setCanDragResize(false);
list.setFields(listField);
list.draw();
If u want all fields to be disabled then you can use:
ListGrid list = new ListGrid();
list.setCanResizeFields(false);
list.setWidth(500);
list.setHeight(300);
ListGridField listField = new ListGridField("first");
ListGridField listField2 = new ListGridField("second");
ListGridField listField3 = new ListGridField("third");
list.setFields(listField,listField2,listField3);
list.draw();
EDIT: you can also set list.setCanReorderFields(false); if u dont want to reorder fields
Regards, Jakov A.
Related
I would like to use FormLayout where one of the fields is visible depending on another field. Is there a way to keep the formatting the same, that is for all the fields after it to stay in their same position when another component is invisible.
Below is the code to reproduce as well as a screenshots of what I would like compared to the current behavior. In essence each time you select the combobox you make the "Year Joined Team" field invisible/visible.
TextField nameTextField = new TextField("Name");
ComboBox<String> teamComboBox = new ComboBox<>("Team");
DatePicker yearJoinedDatePicker = new DatePicker("Year Joined Team");
TextField moreFieldsTextFields = new TextField("More fields");
FormLayout formLayout = new FormLayout();
formLayout.setWidth("600px");
formLayout.setResponsiveSteps(new FormLayout.ResponsiveStep("0", 2, FormLayout.ResponsiveStep.LabelsPosition.TOP));
formLayout.add(nameTextField,
teamComboBox, yearJoinedDatePicker,
moreFieldsTextFields);
teamComboBox.setItems(List.of("One", "Two"));
teamComboBox.addValueChangeListener(change -> yearJoinedDatePicker.setVisible(!yearJoinedDatePicker.isVisible()));
formLayout.setColspan(nameTextField, 2);
add(formLayout);
Ideally the goal is to have the fields below the yearJoinedTeamDatePicker component to stay below so that all other components below continue to be aligned correctly when it's set to be invisible.
Instead what actually happens is that all the components are shifted on field to the left, as if the invisible component is no longer part of the FormLayout. Meaning the moreFieldsTextField is now on a different row, and if everything is setup for two columns every row will be incorrect. I understand that this makes sense in some context but in a FormLayout is there a way to keep the form formatted if a component is invisible?
If for example I had firstname and lastname as two side by side fields they would now be on different rows as shown below:
A very hacky solution would be to add in a Span component or something like that and make it invisible when the yearJoinedDatePicker field is visible, and invisible when it's visible. Basically fill it in with an empty field when it's invisible. That is a hacky workaround but it doesn't seem like an appropriate solution. With that in mind is there a way to keep the formatting/layout if a component is invisible?
What you are trying to achieve is sort of defying the purpose of FormLayout. FormLayout has css flex rules to wrap elements / components by row. Thus if you switch visibility of a component, the behavior is as you described.
One thing you could do, is to wrap "Team" and "Year joined team" inside e.g. HorizontalLayout and set
formLayout.setColspan(horizontalLayout, 2);
See, also my previous answer about FormLayout https://stackoverflow.com/a/69270190/8962195
If you want to keep the place, maybe it's vable for you to set the field ti disabled with setEnabled.
I'm not sure how it would behave, but you could try CSS display: none instead of the setVisibility(false).
i try to implement navigation with key arrow in the grid.
to do this i need to able select one row per row index programmatically.
How can i do this?
thx.
Vaadin Flow Grid has method Grid.select(item), which selects item programmatically. So you need to resolve the item. The best way to get it, is to use Grid.getDataCommunicator() which has the following method, fetchFromProvider:
https://demo.vaadin.com/javadoc/com.vaadin/vaadin-core/10.0.2/com/vaadin/flow/data/provider/DataCommunicator.html#fetchFromProvider-int-int-
So fetchFromProvider(rowIndex,1) returns the item you want to select.
You can use the defined SelectionModel of your grid.
private Grid<Customer> customerGrid = new Grid<>();
customerGrid.getSelectionModel().select([enter your logic for identifying the customer of your wish]);
Use the following API (since Vaadin 17)
Person item = grid.getDataCommunicator().getItem(42);
grid.select(item);
or
Person item = grid.getGenericDataView().getItem(42);
grid.select(item);
Is there a way to create a radiobuttongroup with vertical alignment?
What I did is I created a verticalLayout around my radiobuttongroup shown in the picture below.
What I recieve is this:
What I want is this:
O a O b
How can I do that using a JavaScript-view in sapui5?
Its the columns property which determins how many RadioButton Items will be shown in a single row.
Check the below link: https://openui5.hana.ondemand.com/docs/api/symbols/sap.ui.commons.RadioButtonGroup.html#getColumns .
For you Code, since there are only 2 items, you can set the columns property in the RadioButtonGroup to 2.
var oRBG = new sap.ui.commons.RadioButtonGroup({
columns :2
});
I am developing application using vaadin framework.
I need to add layout(Form) inside a table component. I have created a table with two column,
This is my code
Table table = new Table();
table.addContainerProperty("Id", Integer.class, null);
table.addContainerProperty("Name", String.class, null);
for( int i = 0; i < 50; i++) {
table.addItem(new Object[] {i, "xyz"}, Integer.valueOf(i));
}
table.setSelectable(true);
table.setSizeFull();
When I am clicking on record, I need Form layout which containing TextField's in between the clicked row and next row.
Previously I was using child window and added to the application window, acts as the overlay to the whole page.
But my requirement is the exactly between the two rows in table.
Can any one help, how to do this in Vaadin.
Probably you want edit the all selected records on table. For this you can use Property.ValueChangeListener. When event occurs you can get all selected records and put them to wherever you want. Of course you must create dynamic form elements for every selected record.
the SearchFieldDemo works well for me, but has one problem: when you add a new country to the KeywordFilterList through the menu and that new item is on the bottom of the sorted list, then the user doesn't see anything and is unsure if the new item has been added or not.
A solution would be to make the KeywordFilterList scroll to the new item, but I can't figure out, how to do that. I've tried:
void addElementToList(Country country)
{
_countryList.addElement(country);
_keywordFilterField.updateList();
int index = _countryList.getIndex(country);
System.err.println("XXX index: " + index);
_keywordFilterField.setSelectedIndex(index);
}
But this does not have any effect: the printed index is correct and the KeywordFilterList scrolls, but not to a correct spot.
Any ideas please?
Alex
In the sample app you might have noticed the _keywordFilterField.setKeyword(""); line as the first thing they do before adding a new item to the list. This is to guarantee the new item will be visible in the list. Otherwise with some filter applied the list may not display the new item.
So in your code it looks like you don't handle this point. As a result the index you get with int index = _countryList.getIndex(country); may not be the same as it is in the visible filtered by some current keyword list. BTW, to find the index in the visible list you could use the ReadableList which can be got with _keywordFilterField.getResultList().
So the workflow could be as follows:
reset keyword by _keywordFilterField.setKeyword(""); - now there is no filtering applied so the visible list should include a new item.
add a new item to the underlying collection - _countryList.addElement(country);
call _keywordFilterField.updateList(); to refresh the ListField.
to be on the safe side find an index to scroll to by using the collection got by calling the _keywordFilterField.getResultList()
select the new item with _keywordFilterField.setSelectedIndex(index);