Page 1 of 1

Data Grid form search functionality (filtering)

Posted: Thu Feb 23, 2023 2:30 pm
by markosborne
Hello All,

I have a Data Grid form displaying a very long list (single-word and multi-word text descriptions).

There is a Field on the card, which is used to enter search terms in order to filter the items in the Data Grid form down to a manageable length in oder to make finding items easier. I have implemented basic search functionality using this field script:

global gDataGridArray_A

on textChanged
local tFilteredArray, tFilter
put text of me into tFilter
if tFilter is not empty then
filter elements of gDataGridArray_A where each["TXT"] contains tFilter into tFilteredArray
set the dgData of group "DataGrid_A" to tFilteredArray
else
set the dgData of group "DataGrid_A" to gDataGridArray_A
end if
end textChanged

This works well and only displays items in the Data Grid containing the text entered in the field. For example, if “ard” is entered, only items containing “ard” will be displayed in the Data Grid: "a block of lard", "piece of chard", etc.

Question 1: Is this a good approach in terms of using ‘filter’ and setting the dgData in this way?

I now need to enhance the search functionality so that it will search for multiple part matches of strings. For example, if an item in the list is: “pastel colours and stripes”, I want to be able to type “pas our” to locate it. Or “ast olor ice”. Or “rs tel pes”

Question 2: Any thoughts on how to approach that?

Thanks in advance (for answers or suggestions either question)

Mark

Re: Data Grid form search functionality (filtering)

Posted: Thu Feb 23, 2023 3:16 pm
by markosborne
Correction:

Data Grid table NOT form

Re: Data Grid form search functionality (filtering)

Posted: Sun Feb 26, 2023 4:28 pm
by stam
Hi Mark,
I use this approach all the time, so I guess it's fine :)
it will work for both table and form data grids

Regarding your other question: if I understood correctly, you want to use multiple word fragments to search filter by a key?
I haven't tested but assume just replacing spaces with wildcards (asterisks) in the text contained in the filter field should allow this.

Code: Select all

put "*" & replaceText(the text of me, "\s", "*") & "*" into tFilter 
This replaces all spaces with wildcards, pre- and postfixes the search text with wildcards as well.
This should provide what you need - alternatively you can use regex but that depends on how handy you are with regex (most aren't!)

HTH
Stam

Re: Data Grid form search functionality (filtering)

Posted: Mon Feb 27, 2023 12:14 pm
by markosborne
Thanks Stam,

I tried your code but it just filters everything out on the first character I type (empties/clears the Data Grid).

I'll give the regex a go (but I'm no expert...).

Best

Mark

Re: Data Grid form search functionality (filtering)

Posted: Mon Feb 27, 2023 7:19 pm
by stam
Hi Mark,

sorry that didn't work - didn't really have the data to test it with, although a quick muck-about in the multiline message box with strings rather than arrays did work.

if you post an example with the data you want to filter I'm sure it can be done fairly easily...

BW
Stam

Re: Data Grid form search functionality (filtering)

Posted: Mon Feb 27, 2023 10:19 pm
by jacque
I usually just do repeated filtering for as many matches as I need. For example:

Code: Select all

put “ast olor ice” into tFilters
put gDataGridArray_A into tFilteredArray
repeat for each word w in tFilters
   filter elements of tFilteredArray where each["TXT"] contains w
end repeat

Re: Data Grid form search functionality (filtering)

Posted: Tue Feb 28, 2023 6:33 am
by markosborne
Thank you Jacque,

That works just fine.

Much appreciated.

Mark

Re: Data Grid form search functionality (filtering)

Posted: Tue Feb 28, 2023 6:41 am
by markosborne
And thank you for your offer of further help Stam,

You were right, it was fairly easy -- I'm still trying to get used to the syntax and framework...

Best wishes

Mark