Loading Datasource by calling API on typing for a search

On typing in Combobox, I put a delay of 500ms OnValueChanged to call an API to search in the Database to fill the Datasource.
The DataSource is always good, but sometime, the combobox list doesn't refresh correctly. Sometime, the datasource is empty and the last list stay in the UI. How to be sure the list is always showing correctly ?

Here my code (note: The method LoadResultsAsync will call the API and will fill the ResultList (for the DataSource) with a NotifyPropertyChanged)

<comboBox:SfComboBox
                        x:Name="searchComboBox"
                        HeightRequest="40"
                        MaximumDropDownHeight="200"
                        IsEditableMode="true"
                        DataSource="{Binding ResultList}"
                        NoResultsFoundText="{local:Translate NoResultsFound}"
                        DropDownBackgroundColor="#D5D5D5"
                        SelectedDropDownItemColor="#D5D5D5"
                        ValueChanged="ComboBox_OnValueChanged"
                        Watermark="{local:Translate Search}"
                        WatermarkColor="DarkGray"
                        DisplayMemberPath="Name"
                        DropDownTextColor="Black"
                        SelectionChanged="SfComboBox_OnSelectionChanged">
                        <comboBox:SfComboBox.DropDownButtonSettings>
                            <comboBox:DropDownButtonSettings Width="40" Height="40">
                                <comboBox:DropDownButtonSettings.View>
                                    <Label Style="{StaticResource SearchLabelStyle}" FontSize="18" Padding="0,10,0,0"
                                           FontAttributes="Bold" TextColor="DarkGray" />
                                </comboBox:DropDownButtonSettings.View>
                            </comboBox:DropDownButtonSettings>
                        </comboBox:SfComboBox.DropDownButtonSettings>
                    </comboBox:SfComboBox>

        private async void ComboBox_OnValueChanged(object sender, Syncfusion.XForms.ComboBox.ValueChangedEventArgs e)
        {
            this.cts?.Cancel();

            this.cts = new CancellationTokenSource();
            CancellationToken ctoken = this.cts.Token;

            try
            {
                int millisDelay = this.TextChangedDelay > 0 ? this.TextChangedDelay : 500;
                await Task.Delay(millisDelay, ctoken);

                if (ctoken.IsCancellationRequested)
                {
                    return;
                }

                try
                {
                    if (string.IsNullOrEmpty(e.Value))
                    {
                        this.searchComboBox.DataSource = null;
                    }
                    else
                    {
                        if (e.Value.Length >= 3)
                        {
                            Device.BeginInvokeOnMainThread(
                                async () =>
                                    {
                                        await this.viewModel.LoadResultsAsync(e.Value);
                                    });
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            catch (OperationCanceledException)
            {
                // Expected
            }
        }

3 Replies

RB Rabhia Beham Kathar Mideenar Syncfusion Team August 10, 2020 10:36 AM UTC

Hi Sébastien,

Greetings from Syncfusion.

We have prepared a sample with our understanding and we have checked the issue in SfComboBox with NuGet Package (18.2.0.48) and we are unable to reproduce the issue from our end. Please check with the sample with which we have ensured,

Sample:
https://www.syncfusion.com/downloads/support/directtrac/general/ze/Dynamicsample-1165887765

Video: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DynamicVideo.mov2057863124

Please check with the above sample and if still exists,

* Please modify the above sample with the issue reproducing steps,
* Provide additional details of the issue and also provide video representation of the issue if possible since we are unaware of the exact application scenario.

The above will help us identify the problem and provide the solution at the earliest possible.

Regards,
Rabhia Beham.




AD Amit Deshpande December 15, 2020 08:37 AM UTC

Hello,

We are trying same as per your suggestion but with api call sfcombo box is not working. It is not showing any search result/data

Referance:
https://www.syncfusion.com/forums/156728/loading-datasource-by-calling-api-on-typing-for-a-search

If we try with below code then it is working and showing result

for (int i = 1; i <= 10; i++)
{
VehicleModel model = new VehicleModel();
model.OID = i;
model.Kennzeichen = vehicleNumber + i;
VehiclesCollection.Add(model);
}


If  data fetched from API then SfComboBox not showing any result
foreach (var item in vehicleData.value)
{
      if(VehiclesCollection.Count< 10)
      {
              VehicleModel model = new VehicleModel();
                model.OID = item.OID;
                model.Kennzeichen = item.Kennzeichen;
                VehiclesCollection.Add(model);
      }
}


Please check and update us or please schedule call ( urgent ) 

Thanks,
Amit Deshpande
                     





SS Suganya Sethuraman Syncfusion Team December 16, 2020 11:38 AM UTC

Hi Amit,

We have analyzed the reported issue. We have prepared a sample based on the information provided. We have tried to replicate the reported issue at our end, we are afraid that we are not able to reproduce the issue at our end. We have attached sample for your reference.

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/APISfComboBox1178836577

Since we are not aware of your exact application scenario, we were not able to reproduce this issue at our end, so can you please provide complete runnable sample. This will be helpful for us to investigate further and provide you a better solution at the earliest.

Regards,
Suganya Sethuraman.   
 


Loader.
Up arrow icon