Completed
Last Updated: 18 Jan 2024 09:10 by ADMIN
Aditya
Created on: 17 Sep 2020 08:39
Category: Grid
Type: Feature Request
46
Allow SearchBox to work with other data types

I want to be able to enter numbers and the grid to filter numeric fields too according to those numbers. Enums would be nice too.

 

**Admin Edit**

The feature request will be researched and evaluated. It contradicts to our datasource filtering logic that relies on the type of the fields. Thus, it is highly possible that we will handle the task through a knowledge base example.

**Admin Edit**

 

13 comments
ADMIN
Dimo
Posted on: 18 Jan 2024 09:10

Hello Gert,

When we polled the community for additional feedback and requirements for this feature, we didn't get enough information. As a result, we will continue with a custom SearchBox component until enough customers provide information about their exact needs. See section "Next Steps" from my previous message and feel free to elaborate.

Regards,
Dimo
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources!
Gert
Posted on: 18 Jan 2024 08:35

Hi,

will there be a built-in solution?

ADMIN
Dimo
Posted on: 11 Apr 2022 17:18

Hello everyone,

Let me provide an update about this request.

Background

A single textbox to search in multiple columns and data types raises questions about:

  • What should be the default behavior with regard to numbers and dates? Should it be "contains" or should it be "equal to"?
  • What should be customizable?

It's certain that different scenarios or users will require different behavior. At the same time, "be able to customize everything" is not optimal or even possible either.

The Grid already provides two filtering modes, which handle the standard use cases. So, the global search UI should be able to do something different and be flexible.

What we did

We implemented a Razor component for this multi-type search textbox. For the time being, the component is not built-in inside UI for Blazor, but you will still be able to reuse it and customize it. I have linked the code at the bottom of this post. We will appreciate everyone's feedback if the suggested behavior fits your use cases and requirements.

How it works

The component will do the following:

  • Handle the user input.
  • Try to parse the search string to other data types (number, date).
  • Build a complex filter descriptor that targets all applicable Grid model properties.

At this point, you only need to pass the filter descriptor to the Grid state.

Default behavior

The default behavior will be:

  • String values will be filtered by "contains".
  • Numeric, date and enum values will be filtered by "equal to". Searching in numeric fields by "contains" is not supported.
  • As an additional example, we are showing how to search for dates by the year only.
  • Strings that cannot be parsed to a specific data type (such as "123 abc"), will not produce non-string search results. You will be able to customize this behavior, for example split the search string to chunks, etc. When I say "customize", this means manual coding.

Example

Here is the example with the reusable Razor component: Grid Knowledge Base: Search in Numeric Fields

Next Steps

Due to the ambiguous nature of this feature, we need to be very certain what do customers need and if it is practical to implement it.

I am setting the status of this thread as "Need more information" while gathering feedback. The information we receive from you will determine if we add a built-in feature to the Grid and how exactly.

So, we expect two types of comments now -

  • Description of scenarios - how do your users want to search and what results do they expect. This is the "input" and "output" part of the picture. For example - do users expect "contains" or "equal to" searching for numbers? Why do users search for numeric and date values in the SearchBox, instead of use the standard filtering UI?
  • Technical comments, such as the ones by Martin Herløv and René. This is the "black box" from users' point of view, but the practical aspect for all of you - our customers. What type of configuration and customizations do you need? What will be most convenient for you?

Regards,
Dimo
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/.

Martin Herløv
Posted on: 06 Jan 2022 12:27

No need to overthink this.

Treat all numbers as integers. Dates, use the UI Culture.

For everything else add an option for a custom compare function.

John Campion
Posted on: 11 Dec 2020 22:21
Wanted to see if we could also get enum searches in this?   
René
Posted on: 22 Sep 2020 05:59

Hi Marin,

having a default way to search in Non-String columns and being able to alter the behavior for special use-cases within an event-handler would be a good way to go. 

Regards,

René

ADMIN
Marin Bratanov
Posted on: 21 Sep 2020 13:51

Hi René,

If automatic parsing becomes available, I'd imagine that the current culture would be used and the .TryParse method of double, but we are collecting this feedback, and maybe such features may become available. The thing about the "equals" check is that it's unclear whether it should be equals, less than or greater than - different cases will need it every which way.

I'm also thinking that the best flexibility would be achieved through an event that provides you the string value of the user input, and the filter descriptor the grid would build, so you could add to it or alter it as needed - you won't have to start from scratch to customize things. Would that be useful to you? It would, for example, let you add filters for fields that are not currently visible, which is not the default behavior of the searchbox for UX reasons.

 

Regards,
Marin Bratanov
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).

René
Posted on: 21 Sep 2020 07:02

Hello Marin,

if the searchbox contains more than something parsable to a date I would not display any results.  That's why I would like to pass a list of valid formats.  With that a date would have a clear definition so no guessing is needed.

For numbers I would like a "DecimalSeparator"  and a "NumberEqualThreshold" Parameter.

I would then convert any Number (int/float/double/decimal) to double and do the following

if (Math.Abs(searchboxValue - columnValue) < NumberEqualThreshold) { // include in results }

Exposing an event for the searchbox for custom filter/search logic would not

help me much personally because then it would be more or less the same as

just keeping my custom implementation of a searchbox.

ADMIN
Marin Bratanov
Posted on: 18 Sep 2020 07:38

Hello René,

How would you solve the case where the searchbox contains more than something parsable to a date, assuming there is a list of such formats? How would numbers be handled, especially decimal values for integer columns? What would be the filter operator for such fields where a "contains" does not exist?

In another approach - would exposing an event for the searchbox so you can implement your own filtering be something that would help? It would let you parse the string in the desired fashion and add filters to the grid through its state for different fields depending on their type and your preferred logic.

 

Regards,
Marin Bratanov
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/.

René
Posted on: 18 Sep 2020 06:13

Hello Marin,

in our own implementation of a searchBox we do this for enums:

if(enumColumnValue.ToString().ToLowerInvariant().Contains(SearchString.ToLowerInvariant()))

{

   // include in results

}

and this for dateTimes:

string[] validFormats = {"dd.MM.yyyy", "dd.MM.yy", "dd.MM.", "MM.yyyy", "MM.yy"};
var searchStringIsDate = DateTime.TryParseExact(SearchString?.ToLowerInvariant(),
                    validFormats,
                    System.Globalization.CultureInfo.InvariantCulture,
                    System.Globalization.DateTimeStyles.None,
                    out var date);

if(searchStringIsDate && d.WunschLiefertermin <= date)

{

   // include in results

}

It would be great if a validDateTimeFormats Array could be configured for the searchBox and if a FilterLogicForDatTime Parameter could be set (we use seq but others could be needed as well).

Regards,

René

 

ADMIN
Marin Bratanov
Posted on: 17 Sep 2020 23:08

Hi all,

Do leave the types of data you want the searchbox to use, and I'd also appreciate some examples on the expected behavior for things that aren't strings - for example, what should be searched for enums, for dates (format?), separators for decimals values.

The issue here is that in that input the user writes an arbitrary string and there is no certain way to know what they want to filter on - how to know if it's a number or can it be a date (there are a myriad ways to write a date and its not feasible to try to parse the infinite amount of possible format strings).

Once this gets reviewed we will have the demand and we will be able to know what can and cannot be done.

What I can say at this point is that the Kendo searchbox also works with strings, try it in this dojo and type "9", for example: https://dojo.telerik.com/osoHijEV (screenshot attached at the end of this post). The same is listed for server operations in the UI for ASP.NET Core documentation and Blazor is always equivalent to server operations in that sense - it uses the same DataSourceRequest and DataSourceResult concepts that you'd use in the controller actions for that grid, and the same filter descriptor classes where a Contains operator is only possible for strings in .NET.

 

Regards,
Marin Bratanov
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).

Steven
Posted on: 17 Sep 2020 14:39
Would it be possible to filter on date fields too with the SearchBox?
Aditya
Posted on: 17 Sep 2020 12:40

ASP.NET Core Grid supports searching on number fields - https://demos.telerik.com/aspnet-core/grid/search-panel

Hope Blazor Grid too supports searching on number fields in near future