Under Review
Last Updated: 22 Sep 2020 05:59 by René
Aditya
Created on: 17 Sep 2020 08:39
Category: Grid
Type: Feature Request
15
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.
8 comments
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