Hello Syncfusion Team,
I'd like to know if there is an easy way to select identical values from the popup list several times within the MultiSelect control?
My use case would be to use this dropdown control as sort of expression editor for formulas with predefined items (which can be selected several times) originated from the popup list and dynamically added values based on AllowCustomValue setting to true. When I try to add an clone of an already selected item with identical text value, but let's say different Id which would be OK for my scenario, with AddItemsAsync when OnChipTag event fires, this is only working when AllowCustomValue is set to false. Then I could tag this items as cloned item and would remove them again from value list when OnValueRemove event fires. But as I said, AddItemsAsync unfortunately not working in this scenario.
Please refer to my sample code snippet attached to this post.
Can you help me with my issue? Thanks a lot in advance for your support.
Best regards,
Florian
Attachment: ExpressionEditor_4138845.zip
Hello Support Team,
any news about my question? Appreciate your help, thank you!
Best regards,
Florian
|
<div class="container-fluid">
<div class="col-4">
<SfMultiSelect @ref="formulaMultiSelect" TValue="int[]" TItem="TechnicalParameter" Placeholder="Define formula" DataSource="@technicalParameters" AllowCustomValue=true AllowFiltering="true" Mode="@VisualMode.Box">
<MultiSelectFieldSettings Text="Name" Value="ID" />
<MultiSelectEvents TValue="int[]" TItem="TechnicalParameter" OnChipTag="@OnChipTag" OnValueRemove="@OnValueRemove" CustomValueSpecifier="@CustomValueSpecifier" Filtering="@CustomFilter" />
<MultiSelectTemplates TItem="TechnicalParameter">
<NoRecordsTemplate>
<div>
<div id="nodata">No matched item, would you like to add it to the list as a new item?</div>
<SfButton id="btn" class="e-control e-btn custom-button" @onclick="@AddItem">Add New Item</SfButton>
</div>
</NoRecordsTemplate>
</MultiSelectTemplates>
</SfMultiSelect>
</div>
</div>
<style>
.e-chips.expression, .e-chips.expression:hover {
background-color: darkblue;
}
.e-chips.operator, .e-chips.operator:hover {
background-color: orange;
}
</style>
@code {
private SfMultiSelect<int[], TechnicalParameter>? formulaMultiSelect;
private int cloneId = 1000;
private string Custom { get; set; }
Random rnd = new Random();
private ObservableCollection<TechnicalParameter> technicalParameters = new ObservableCollection<TechnicalParameter>
{
new TechnicalParameter() { ID = 1, Name = "IntParam1", Description = "First int parameter", DataType = typeof(int).ToString(), Quantity = 15 },
new TechnicalParameter() { ID = 2, Name = "IntParam2", Description = "Second int parameter", DataType = typeof(int).ToString(), Quantity = 20 },
new TechnicalParameter() { ID = 3, Name = "+", Description = "+ operator", DataType = typeof(string).ToString(), Quantity = float.MinValue, IsOperator = true },
new TechnicalParameter() { ID = 4, Name = "-", Description = "- operator", DataType = typeof(string).ToString(), Quantity = float.MinValue, IsOperator = true }
};
private void CustomFilter(FilteringEventArgs args)
{
this.Custom = args.Text;
}
private async Task OnChipTag(TaggingEventArgs<TechnicalParameter> args)
{
args.SetClass = args.ItemData.IsOperator ? "operator" : "expression";
//await formulaMultiSelect.AddItemsAsync(new ObservableCollection<TechnicalParameter> { new TechnicalParameter() { ID = cloneId++, Name = args.ItemData.Name, Description = args.ItemData.Description , DataType = args.ItemData.DataType, Quantity = args.ItemData.Quantity, IsClone = true, IsOperator = args.ItemData.IsOperator }});
}
private void CustomValueSpecifier(CustomValueEventArgs<TechnicalParameter> args)
{
double res = 0;
// Allow only numeric values
if (!double.TryParse(args.Text, out res))
args.Cancel = true;
}
private async Task AddItem( Object sender)
{
var customData = new TechnicalParameter() { ID = rnd.Next(cloneId), Name = this.Custom };
await this.formulaMultiSelect.AddItems(new ObservableCollection<TechnicalParameter> { customData });
technicalParameters.Add(customData);
await this.formulaMultiSelect.HidePopupAsync();
}
private void OnValueRemove(RemoveEventArgs<TechnicalParameter> args)
{
if (args.ItemData.IsClone)
technicalParameters.Remove(args.ItemData);
}
private class TechnicalParameter
{
public int ID { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public string? DataType { get; set; }
public float Quantity { get; set; }
public bool IsClone { get; set; }
public bool IsOperator {get; set; }
}
} |
Hello,
thanks a lot for your reply, but your sample isn't working properly! If I use the button "Add new item" within the NoRecordsTemplate, all previous selected items within the control will be deleted and the newly added item isn't selected properly. So up to now I still cannot achieve what I want, please refer to this screenshot:
I'd like to add/select and chip multiple identical items from a predefined List (DataSource) and user-defined custom values. I'm still a step further (like you can see) but not at the end of the journey. I still have problems to handle custom values properly.
Can you please re-check this issue. Thanks again for your help.
Regards,
Florian