Blazor: setting Chips

I have the following Chips defined:

            <SfChip @ref="SfChipSet1">
                <ChipEvents></ChipEvents>
                <ChipItems>
                    <ChipItem Text="Whenever" Value="whenever"></ChipItem>
                    <ChipItem Text="At Time" Value="attime"></ChipItem>
                </ChipItems>
            </SfChip>

The intellisense for the SelectChips method displays: "A function that selects chip items based on given index. Values of the chips which are to be selected should be passed"

I tried the following, but no chips are selected:

                string[] chips = { "whenever" };
                SfChipSet1.SelectChips(chips);

How do I properly select chips?

Thanks.

3 Replies 1 reply marked as answer

SS Sharon Sanchez Selvaraj Syncfusion Team January 22, 2021 09:48 AM UTC

Hi Glenn, 

Thanks for contacting Syncfusion support. 

Based on your requirement, selection of chips can be done in two ways. 

Solution 1: 
 
When using SelectChips method, we suggest you to specify the Selection type. The Selection type can be either Single or Multiple. 

 
<SfButton OnClick="click" Content="Select Chip"></SfButton> 
<SfChip @ref="SfChipSet1" Selection="SelectionType.Single"> 
    <ChipItems> 
        <ChipItem Text="Whenever" Value="whenever"></ChipItem> 
        <ChipItem Text="At time" Value="attime"></ChipItem> 
    </ChipItems> 
</SfChip> 
 
@code{ 
    SfChip SfChipSet1; 
    private void click() 
    { 
        string[] chips = { "attime" }; 
        SfChipSet1.SelectChips(chips); 
    } 
} 
 
 

Solution 2: 
 
By using the property SelectedChips, the Value specified will be selected.  Refer to the below code 

 
<SfChip @ref="SfChipSet1" SelectedChips="chips" Selection="SelectionType.Multiple"> 
    <ChipItems> 
        <ChipItem Text="Whenever" Value="whenever"></ChipItem> 
        <ChipItem Text="At time" Value="attime"></ChipItem> 
    </ChipItems> 
</SfChip> 
 
@code{ 
    SfChip SfChipSet1; 
    string[] chips = { "attime", "whenever"};    
} 
 
 

We have attached a sample for your reference. 


Please refer to our demos and documentation link for more details on Chip component. 



Please get back to us, if you need any further assistance. 

Regards, 

Sharon Sanchez S. 
 


Marked as answer

PR Preben September 28, 2022 12:44 AM UTC

Should be possible to have a generic value in the chip Value property, so we can pass a selected T type back thru the event. String type is too limited.



IL Indhumathy Loganathan Syncfusion Team September 29, 2022 03:47 PM UTC

Hi Preben,


We have considered the scenario "Provide generic type support for property SelectedChips in Blazor Chips component" as a feature which will be included in any of our upcoming releases. Generally, we will plan and implement the features based upon the feature rank, customer request count, and wish-list plan. You can track the status of this feature through the below portal link.


Feedback link: https://www.syncfusion.com/feedback/28429/provide-support-for-string-array-data-source-in-listview


We appreciate your patience.


Regards,

Indhumathy L


Loader.
Up arrow icon