Hi Özgür,
Greetings from Syncfusion support.
We have checked the reported requirement.
Query 1: I have two major problems on combobox control for Blazor server app.
Firstly I want to Bind an integer value as an Id value for the combobox, but it is a big problem to bind an integer value.
<SfComboBox TValue="string" TItem="MachineGroupDto" Value="_mDto.IdStr" Placeholder="-- Please select --" AllowFiltering="true" DataSource="@_machineGroupList">
<ComboBoxFieldSettings Text="GroupName" Value="Id"></ComboBoxFieldSettings>
</SfComboBox>
If I make TValue = "int", I can't bind the control. Solution is making int to int?
But I can't do it because I use this dto in my data, business projects. This is a foreign key of a table and it cannot be null. Why I have to do it int?
I made a string version of my Id value as IdStr to solve this problem. and Transfer this IdStr value to real foreign key field when I save dto to database.
But it has to be easy to bind an integer value as a value parameter. I hope on the next version, Syncfusion can make an improvement about this issue.
Solution:
We provided the int? support because of the below reasons.
ComboBox component is editable. So we can delete the value using clear button and delete key. At that time, the value becomes null. To handle that case we have provided the TValue as nullable.
Also we can provide the TValue as int if you are not going to clear the input value using delete key or ShowClearButton. Also, we can use the TValue as int by disabling the ShowClearButton.
Query 2: My second problem is display text of the selected item on the combobox text area.
Imagine my machine group table is like below;
1: Group 1
2: Group 2
3: Group 3
...
when I sent 3 as IdStr value, component display 3 on the text. but I should display Group 3 as a text value of combobox.
So what should I do?
Solution:
By default while passing the id then, corresponding text property will be shown in the component. We suspect that you have bind the dataSource’s value property as int and binded the TValue as string. Else, if loaded the data asynchronously, then set the value property after the dataSource has been loaded.
If you want to get the selected value’s text property from the component’s instance in the change or select event. Kindly refer the below code,
|
<SfComboBox @ref="comboboxObj" TValue="int" TItem="Countries" ShowClearButton="false"Placeholder="e.g. Australia" Value="@ComboVal" DataSource="@Country">
<ComboBoxFieldSettings Text="Name" Value="Code"></ComboBoxFieldSettings>
<ComboBoxEvents TValue="int" ValueChange="onChange"></ComboBoxEvents>
</SfComboBox>
public int ComboVal = 1;
public void onChange(ChangeEventArgs<int> e)
{
text = this.comboboxObj.Text;
} |
Please find the sample below,
Regards,
Sevvandhi N