Concatenate Text field in DropDownListFieldSettings

Hi, currently my DropDownListFieldSettings has Text = "FirstName". I would like for it to display LastName as well.
ex: <DropDownListFieldSettings Text="FirstName + LastName" />

Question:
How do I attach 'Text' to more than one value in 'DropDownListFieldSettings'?



Attachment: Filter_first_and_last_name_157258af.zip

1 Reply 1 reply marked as answer

BC Berly Christopher Syncfusion Team May 28, 2021 11:49 AM UTC

Hi Kenney, 
  
We have checked the shared video demonstration. In the shared video demonstration, you have concatenated the FirstName and LastName with help of template but its available in the different field in the data source property. We would like to know you that filtering will be performed based on single field by default. So, the reported issue has been occurred.  
  
We can overcome this issue with help of predicate which is used to filter the value from the multiple fields. Here, we have showcased the FirstName and LastName with space. So, we need to split the FirstName and LastName with space character and pass into the predicate and Filter method to achieve the requested requirement. 
  
<SfDropDownList @ref="dropObj" TValue="string" AllowFiltering="true" TItem="GameFields" PopupHeight="230px" Placeholder="Select a game" DataSource="@Games"> 
    <DropDownListFieldSettings Text="FirstName" Value="ID"></DropDownListFieldSettings> 
    <DropDownListEvents TValue="string" TItem="GameFields" Filtering="onFilter"></DropDownListEvents> 
    <DropDownListTemplates TItem="GameFields"> 
        <ValueTemplate> 
            <span class='name'>@((context as GameFields).FirstName) @((context as GameFields).LastName)</span> 
        </ValueTemplate> 
        <ItemTemplate> 
            <span class='name'>@((context as GameFields).FirstName) @((context as GameFields).LastName)</span> 
        </ItemTemplate> 
    </DropDownListTemplates> 
</SfDropDownList> 
@code { 
        SfDropDownList<string, GameFields> dropObj; 
    public class GameFields 
    { 
        public string ID { get; set; } 
        public string FirstName { get; set; } 
        public string LastName { get; set; } 
    } 
    private List<GameFields> Games = new List<GameFields>() { 
        new GameFields(){ ID= "Game1", LastName= "Olsen", FirstName="Hans" }, 
        new GameFields(){ ID= "Game2", LastName= "Fuller", FirstName="Andrew" }, 
        new GameFields(){ ID= "Game3", LastName= "Bond", FirstName="James" }, 
     }; 
    public void onFilter(FilteringEventArgs args) 
    { 
        var firstField = ""; 
        var secondField = ""; 
        var splitText = args.Text.Split(" "); 
        firstField = splitText[0]; 
        if (splitText.Length == 2) 
        { 
            secondField = splitText[1]; 
        } 
        args.PreventDefaultAction = true; 
        var pre = new WhereFilter(); 
        var predicate = new List<WhereFilter>(); 
        predicate.Add(new WhereFilter() { Condition = "or", Field = "FirstName", value = firstField, Operator = "contains", IgnoreAccent = true, IgnoreCase = true }); 
        predicate.Add(new WhereFilter() { Condition = "or", Field = "LastName", value = secondField, Operator = "contains", IgnoreAccent = true, IgnoreCase = true }); 
        pre = WhereFilter.Or(predicate); 
        var query = new Query().Where(pre); 
        this.dropObj.Filter(Games, query); 
    } 
} 
 
  
Screenshot: 
  
 
  
  
Regards, 
Berly B.C 


Marked as answer
Loader.
Up arrow icon