Can I use complex type with multi select?

Hi,


Please take a look of attached project. I am trying to use TValue="List<Countries>" instead of string[] but it is showing [object, object] as a selected value when you try to edit the row. Index.razor file


Attachment: BlazorApp1_15e82146.zip

5 Replies 1 reply marked as answer

PM Ponmani Murugaiyan Syncfusion Team March 14, 2022 07:34 AM UTC

Hi Rohan, 

We have provided the support for “collection of object type to Value property” for the Multiselect component in the version 18.4.42. Please find the release notes below for reference . 


So, we suggest you to upgrade to the mentioned version or to the latest to get rid of this issue. Please find the modified version in the attached sample working as expected. 


Regards, 
Ponmani M 



RO rohan replied to Ponmani Murugaiyan March 26, 2022 11:35 PM UTC

Hi Ponmani,

Thank you for the reply and providing the sample. I tried with the sample but when you edit row => change some selection in dropdown => click on update and then reclick on Edit it is not storing selected values to 

public List<Countries> SelectedCountries { get; set; } of Order class. It is clearing out all the values.


can you please help for that?


Thanks & Regards





PM Ponmani Murugaiyan Syncfusion Team March 28, 2022 12:34 PM UTC

Hi Rohan, 

Query: I tried with the sample but when you edit row => change some selection in dropdown => click on update and then reclick on Edit it is not storing selected values 
 
We have prepared sample based on your requirement and used the OnValueRemove and OnValueSelect events to fetch the modifications done in SelectedCountries property and then used the OnActionBegin event to save the modified value changes of SelectedCountries property.  


<GridEvents OnActionBegin="OnActionBegin" TValue="Order"></GridEvents> 
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"> 
    <EditTemplate> 
        @{ 
            var contextval = (context as Order); 
            _selectedLineIds = contextval.SelectedCountries; 
        } 
        <SfMultiSelect Value="@_selectedLineIds" TValue="List<Countries>" TItem="Countries" Placeholder="e.g. Australia" Mode="VisualMode.CheckBox" DataSource="@Country" ShowDropDownIcon="true"> 
            <MultiSelectFieldSettings Value="Code" Text="Name"></MultiSelectFieldSettings> 
            <MultiSelectEvents OnValueRemove="OnValueRemove" OnValueSelect="OnValueSelect" TItem="Countries" TValue="List<Countries>"></MultiSelectEvents> 
        </SfMultiSelect> 
    </EditTemplate> 
</GridColumn> 
 
 
  private List<Countries> _selectedLineIds = new List<Countries>(); 
    public void OnValueSelect(SelectEventArgs<Countries> args) 
    { 
        //add the selected items from multiselect to custom List  
        _selectedLineIds.Add(args.ItemData); 
    } 
    public void OnValueRemove(RemoveEventArgs<Countries> args) 
    { 
        //remove the unselected items from multiselect to custom List  
        _selectedLineIds.Remove(args.ItemData); 
    } 
 
    public void OnActionBegin(ActionEventArgs<Order> args) 
    { 
        if (args.RequestType.Equals(Action.Save)) 
        { 
            //assign the seelcted itesm from multiselect dropdown to args.Data  
            args.Data.SelectedCountries = _selectedLineIds; 
        } 
    } 

Regards, 
Ponmani M 



RO rohan replied to Ponmani Murugaiyan April 3, 2022 06:34 PM UTC

Hi Ponmani,

Thank you for the sample and reply. It worked for me.


Regards,

Rohan


Marked as answer

PM Ponmani Murugaiyan Syncfusion Team April 7, 2022 05:13 AM UTC

Hi Rohan,


We are glad to hear that the issue has been resolved in your end. Please get back us if you need further assistance.


Regards,

Ponmani M


Loader.
Up arrow icon