We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

IEnumerable<string> as Datasource?

Hi,

the examples for the Autocomplete use always objects with propertties as data source. How can one attach a straightforward IEnumerable<string> or List<string>? The following code does not succeed and the popup states 'The Request Failed'.


<EjsAutoComplete TValue="string" Placeholder="e.g. Australia" DataSource="@LocalData">
</EjsAutoComplete>
@code {

List<string> LocalData = new List<string> { "Australia","Bermuda","Canada","Cameroon","Denmark","France"};

}
The documentation for Autocomplete has no information about this. I guess the AutoCompleteFieldSettings could be helpfull. But how to configure if no object with properties is bound but a plain string?

Sincerly, Axel.


3 Replies

SP Sureshkumar P Syncfusion Team February 3, 2020 09:55 AM UTC

Hi Axel, 
 
Greetings from Syncfusion support. 
 
We have checked the reported requirement. We don't have string dataSource support for the autocomplete component. So as of now, you can convert the string array to list type as mentioned below code snippet 
 
 
List<string> CountryList = new List<string> { "Australia", "Bermuda", "Canada", "Cameroon", "Denmark", "France" }; 
 
protected override void OnInitialized() 
{ 
    LocalData = CountryList.Select(x => new CountryData() 
    { 
            CountryName = x 
        }).ToList(); 
} 
 
We have already considered it as feature, and it will be included in our upcoming volume-1 release. Which is expected to be rolled out on end of March 2020. We appreciate your patience until then. You can track the status of the feature in the below feedback link from below.   
 
 
Regards, 
Sureshkumar P 



AX axl February 8, 2020 11:29 AM UTC

Okay, I get it. Thank you.
No problem at the moment, but I just want to make sure I didn't miss anything and use an additional proxy class for no reason. Especially since the documentation explicitly talks about string arrays (https://ej2.syncfusion.com/blazor/documentation/autocomplete/getting-started/#binding-data-source: ...Here, an array of string values is passed to the AutoComplete component ...). Even if the actual code example does not match the text at this point - a model class is bound and not an array. The documentation surely needs some more attention to be more precise.

Sincerly, Axel.


SP Sureshkumar P Syncfusion Team February 10, 2020 10:10 AM UTC

Hi Axel, 
 
Thanks for the valuable suggestion. We will modify the content and refresh the documentation soon. We will intimate you once the document will be published. 
 
Regards, 
Sureshkumar P 


Loader.
Live Chat Icon For mobile
Up arrow icon