DxComboBox<TData, TValue>.Buttons Property
Allows you to add command buttons to the ComboBox.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v23.2.dll
NuGet Package: DevExpress.Blazor
Declaration
[Parameter]
public RenderFragment Buttons { get; set; }
Property Value
Type | Description |
---|---|
RenderFragment | A collection of buttons (UI fragments). |
Remarks
The ComboBox has the built-in button that invokes a drop-down menu. You can use the ShowDropDownButton property to hide this button.
You can also add custom command buttons to the ComboBox:
- Add the
<Buttons></Buttons>
tag to the component’s markup to define theButtons
collection. Fill the
Buttons
collection. The following buttons are available:- DxComboBoxDropDownButton - A button that invokes a drop-down menu (can be added to the DxComboBox<TData, TValue> only).
- DxEditorButton - A custom button displayed in an editor.
Set up button properties to customize the buttons:
CssClass
Position
- and so on
Buttons are displayed in an editor in the following order:
- The “Clear” button
- Custom buttons and customized default buttons (in the same order as they appear in markup)
- Built-in buttons
The code below adds the Add Employee button to the ComboBox.
<DxComboBox Data="@Data"
TextFieldName="@nameof(Employee.Text)"
@bind-Value="@SelectedEmployee"
CssClass="dx-demo-editor-width">
<Buttons>
<DxEditorButton IconCssClass="editor-icon editor-icon-add"
Tooltip="Add an employee"
Click="@(_ => OnButtonClick())" />
</Buttons>
</DxComboBox>
@code{
IObserver<string> toasterRef;
IEnumerable<Employee> Data { get; set; }
Employee SelectedEmployee { get; set; }
bool AddEmployeePopupVisible { get; set; }
protected override async Task OnInitializedAsync() {
Data = await NwindDataService.GetEmployeesAsync();
SelectedEmployee = Data.FirstOrDefault();
}
void OnButtonClick() {
AddEmployeePopupVisible = true;
}
void OnEmployeeAdded(Employee newEmployee) {
AddEmployeePopupVisible = false;
if (newEmployee != null) {
Data = Data.Append(newEmployee);
}
}
}
We do not recommend that you use conditional render within the <Buttons></Buttons
tag.
This may cause an incorrect button order. The following example demonstrates a case when the Button1
may change its position.
<Buttons>
@if(condition) {
<DxEditorButton Text="Button1"/>
}
<DxEditorButton Text="Button2"/>
<DxEditorButton Text="Button3"/>
</Buttons>
If you need to hide a button, set the Visible
property to false
.