Add dropdown button to component - vaadin

I want to add a dropdown button which usually works as an expand / collapse button in a treegrid. I can't seem to find in the documentation how to add a button which is the exact width and height of the dropdown button, e.g. the specific (custom) button class. This dropdown button should be added to a cell component even if it cannot be expanded / collapsed. The outcome should be that the button in the circle should also be present in the place of the x marks.

I am not fully sure in which context you are going to use this button, but here is an example of borderless button, with html caption that uses the same styles than TreeGrid uses for collapse button.
Button btn = new Button();
btn.addStyleNames("v-treegrid-expander","collapsed");
btn.addStyleName(ValoTheme.BUTTON_BORDERLESS);
btn.addClickListener(event -> {
btn.removeStyleName("collapsed");
btn.addStyleName("expanded");
});
layout.addComponent(btn);

Related

ToolbarButton - Insufficient width for caption

I want to add a caption to a toolbar button (with an icon) because if the button is grayed out (disabled) the description is not displayed.
Caption is also displayed if the button is not enabled...
My problem is that I can't figure out how to enlarge the ToolbarButton field to fit the caption.
The caption consists of 3 words and currently only the first word is displayed due to lack of space - relevant code snippet:
toolbarButton = new ToolbarButton();
toolbarButton.setIcon(ImgRes.ICON_PREVIEW);
toolbarButton.setDescription("Preview Button Description");
toolbarButton.setCaption("Preview Button Caption");
toolbarButton.setWidth("100%");
toolbarButton.setEnabled(false);
toolbarButton.addClickListener(e -> onPreviewButtonClicked());
return toolbarButton;
}
Can anyone help me how to solve my problem?
Try to set the min-width of the button so that it will always fit the content inside it:
toolbarButton.setMinWidth("max-content");

How to apply compact to a grid in Vaadin 14 flow through a button

In Vaadin 14 Flow I have the following code:
Grid grid = new Grid();
setupGrid(grid);
Button compactButton = new Button("Compact",
click -> grid.addThemeVariants(GridVariant.LUMO_COMPACT));
Button normalButton = new Button("Normal",
click -> grid.removeThemeVariants(GridVariant.LUMO_COMPACT));
The issue is when I click on the above buttons only the header of the grid seems to be redrawn when the buttons are clicked, the rows below the header (all the rows of the table) do not appear to be affected. They seem to stay at whatever variant they were initially set at when the screen was initially drawn (other than the header). Is there a way to programmatically adjust the theme of the grid through a button?
You can call grid.getDataProvider().refreshAll(); after changing the theme for it to be applied to all rows.

UI-GRID Expandable Grid. Programatically expand one row

I want to hide the + icon in the far left column and add another icon.
When the user clicks the new Icon I want to programatically expand that specific row.
I see there is gridApi.expandable.expandAllRows();
Is there a way to expand just one row?
You can use toggleRowExpansion function, add this attribute to the desired element which will be trigger this toggle:
ng-click="grid.api.expandable.toggleRowExpansion(row.entity)"
If all you want is to change the default plus icon to a different icon, you can simply override the template for the expandableRowHeader.
$templateCache.put('ui-grid/expandableRowHeader',
"<div class=\"ui-grid-row-header-cell ui-grid-expandable-buttons-cell\"><div class=\"ui-grid-cell-contents\"><i ng-class=\"{ 'ui-grid-icon-plus-squared' : !row.isExpanded, 'ui-grid-icon-minus-squared' : row.isExpanded }\" ng-click=\"grid.api.expandable.toggleRowExpansion(row.entity)\"></i></div></div>"
);
You can change the ng-class=\"{ 'ui-grid-icon-plus-squared' : !row.isExpanded, 'ui-grid-icon-minus-squared' : row.isExpanded }\" and change them to a different icon of your choice.

Disable dropdown arrow in a TButton

In Delphi(XE5), you can set the style property to "bsSplitButton" to create a split button, add a dropdown arrow and assign a popup menu(DropDownMenu) to it,
but how can i disable the the drop down arrow without disabling the whole button?

Why doesn't clicking on my TToolButton show the DropdownMenu?

I'm using Delphi 2010 and I have a TToolButton contained by a TToolBar. Assigned to the 'DropdownMenu' property of my TToolButton is a standard TPopupMenu.
The only way I can get the menu to appear is to click on the area pointed to by the red arrow in the image. Currently, clicking the area pointed to by the green arrow shows the button as pressed, but the dropdown menu does not appear.
What I want is if the user clicks anywhere (pointed to by green arrow or red arrow) for the menu to appear. Is it possible to enable this functionality?
The idea of the tbsDropDown style is to have a button that triggers some default action when clicked, but provides more variations of that action in the drop down menu.
If you don't care about the down arrow disappearing, you can set the style to tbsButton and no matter where the button is clicked, it will show the popup menu.
If you are like me and you do want to have the arrow there to indicate that there are more options behind this button, you can call CheckMenuDropdown in the button's OnClicked event handler.
Set Style to tbsButton. Then you can click anywhere to show the drop-down menu, but you will lose the arrow.

Resources