Filtering does not seem to work with Guid

Hi, I've got the following code to display a list of Guids from the database. The code below shows the Guids in the list but when I type in the search box nothing happens.
I tried to change TValue="string" to TValue=Guid" but it comes with the following error:

"System.FormatException: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)."



 <SfDropDownList TValue="string"
                        AllowFiltering="true"
                        TItem="MyModelData"
                        FloatLabelType="FloatLabelType.Never"
                        DataSource="MyData">

            <DropDownListFieldSettings Text="MyGuid" Value="Id"/>
 </SfDropDownList>

@code {


    List<MyModelData> MyData= new List<MyModelData>();


    protected async override Task OnInitializedAsync()
    {
       
        MyData= repo.GetData();
    }

}


If I change the value of 'Text' in the following line, to another string field in my model, the filter works fine. 
 <DropDownListFieldSettings Text="StringField" Value="Id"/>" 


Many thanks!



3 Replies 1 reply marked as answer

BC Berly Christopher Syncfusion Team March 9, 2021 04:34 PM UTC

Hi Alvaro, 
 
Greetings from Syncfusion support. 
 
While checking the reported issue, the issue caused due to provided data source value does not match with the GUID’s default format. So, we suggest you to ensure that the provided data source for the DropDownList component is correctly matched with GUID’s format.  
 
For your convenience, we have prepared the sample by providing the GUID values to the DropDownList component and attached it below. 
 
Please find the .NET fiddle to differentiate the GUID’s with valid and invalid value below. 
GUID with invalid value: https://dotnetfiddle.net/IsUAf2  
GUID with valid value: https://dotnetfiddle.net/IsUAf2  
 
Please find the stack overflow link from below for the GUID type. 
 
Still issue persists, please share any issue reproducing sample or receiving data in the variable called “MyData” that will help us to check and proceed further at our end. 
 
Regards, 
Berly B.C 



AL Alvaro March 10, 2021 09:43 AM UTC

Thanks for the answer but in the example provided the filter  still does not work. Using your example, I added 'AllowFilering=true',  but when I type in the box nothing happens. Search is ignored.

The problem is not loading the data onto the dropdownlist, this I have it working, it's the filtering what does not seem to work on Guids?


<SfDropDownList @ref=@configurations TValue="Guid" TItem="OdqConfigurationModel"  AllowFiltering="true"
                @bind-Value="@currentId" DataSource="@cachedConfigurations" Width="150px">
    <DropDownListFieldSettings Text="Nom" Value="Nom" />
    <DropDownListEvents ValueChange="OnValueChanged" TValue="Guid" TItem="OdqConfigurationModel" />
</SfDropDownList>


BC Berly Christopher Syncfusion Team March 15, 2021 01:39 PM UTC

Hi Alvaro, 
  
We could not filter the GUID values since the Text filed type is string, so the entered value does not match with the provided GUID values. So, we suggest you to convert the GUID value to string and map to the data source and text field for achieve the requested requirement. Kindly refer the below code example.  
  
Here, we have converted the GUID value field to string value in the variable named as “tempData” and generated the data source by including this variable and assign it to the DropDownList component. 
  
<SfDropDownList TValue="Guid" AllowFiltering="true" DataSource="@DataSource" TItem="ModelClass" Width="150px"> 
    <DropDownListFieldSettings @ref="DropField"  /> 
    <DropDownListEvents Created="onCreate" TValue="Guid" TItem="ModelClass" /> 
</SfDropDownList> 
@code { 
    public string val { get; set;  } 
    public DropDownListFieldSettings DropField; 
    public List<ModelClass> DataSource = new List<ModelClass>(); 
    public List<OdqConfigurationModel> cachedConfigurations = new List<OdqConfigurationModel>() 
    { 
        new OdqConfigurationModel(){Nom = new Guid("11223344-5566-7788-99AA-BBCCDDEEFF00")}, 
        new OdqConfigurationModel(){Nom = new Guid("21223344-5566-7788-99AA-BBCCDDEEFF01")}, 
        new OdqConfigurationModel(){Nom = new Guid("31223344-5566-7788-99AA-BBCCDDEEFF02")}, 
        new OdqConfigurationModel(){Nom = new Guid("41223344-5566-7788-99AA-BBCCDDEEFF00")} 
 
    }; 
    public class OdqConfigurationModel 
    { 
        public Guid Nom { get; set; } 
    } 
    public class ModelClass : OdqConfigurationModel 
    { 
 
        public string tempData { get; set; } 
        public ModelClass() { } 
 
        public ModelClass(Guid nom) 
        { 
            this.Nom = nom; 
        } 
 
        public ModelClass(Guid newval, string category) 
        { 
            this.tempData = category; 
        } 
 
    } 
    protected async Task onCreate() 
    { 
        List<ModelClass> DataSource = new List<ModelClass>() ; 
 
        var data = cachedConfigurations.Select(m => m.Nom); 
        foreach (var i in data) 
        { 
            DataSource.Add(new ModelClass() { tempData = i.ToString(), Nom = i }); 
        } 
        this.DataSource = DataSource; 
        this.DropField.Value = "tempData"; 
        this.DropField.Text = "tempData"; 
    } 
} 
 
  
  
Regards, 
Berly B.C 


Marked as answer
Loader.
Up arrow icon