This is a migrated thread and some comments may be shown as answers.

Prevent Blank Lines In Results

3 Answers 97 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Veteran
Jeff asked on 17 Sep 2020, 05:00 PM
When getting results returned back to the autocomplete control that will be displayed to the User, I'd like to filter out blank lines. Lines that are essentially whitespace, of no value to the User. I'd like to filter for that on the client side rather than the server. 

3 Answers, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 21 Sep 2020, 02:09 PM

Hello Jeff,

I am not sure I understand entirely the scenario. One way I can think of is by providing a dataSource.schema.parse function that would remove empty values.

If the above does not help please provide a runnable example where empty lines are returned, so I can suggest a possible approach. 

Regards,
Aleksandar
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

0
Jeff
Top achievements
Rank 1
Veteran
answered on 21 Sep 2020, 02:27 PM
This is the scenario. I have an autocomplete control that gets it's values from a DB table. So for example, if the DB table has ten entries (rows essentially), and two of the rows have blanks values or empty strings, when the values are displayed in the autocomplete dropdown list, I see two empty rows?  I wanted to eliminate those empty lines in the dropdown list from being displayed.  Originally I thought I'd just filter those lines client side.  

What I ended up doing was filtering those blank lines in the server side linq statement when getting the data with....

&& !string.IsNullOrWhiteSpace(x.Vendor))


Follow?

0
Aleksandar
Telerik team
answered on 23 Sep 2020, 10:58 AM

Hello Jeff,

Thank you for the additional details. Indeed in this scenario, you can follow the suggestion from my previous post and configure the schema.parse function.

I created a sample to demonstrate the approach. A call to a mock API would return the following JSON, where the second object has an empty value:

[{"ProductName":"One"},{"ProductName":""},{"ProductName":"Three"}]

In this scenario you can update the function as:

            schema:{
              parse:function(response){
                var products = [];
                for (var i = 0; i < response.length; i++) {
                  if(response[i].ProductName !=""){
                    var product = {
                      ProductName: response[i].ProductName
                    };
                    products.push(product);
                  }
                }
                return products;
              }
            }

Here is the runnable example for you to review. I hope this helps.

Regards,
Aleksandar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
AutoComplete
Asked by
Jeff
Top achievements
Rank 1
Veteran
Answers by
Aleksandar
Telerik team
Jeff
Top achievements
Rank 1
Veteran
Share this question
or