Data Grid form search functionality (filtering)
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 15
- Joined: Sat Mar 20, 2010 6:03 pm
Data Grid form search functionality (filtering)
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
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
-
- Posts: 15
- Joined: Sat Mar 20, 2010 6:03 pm
Re: Data Grid form search functionality (filtering)
Correction:
Data Grid table NOT form
Data Grid table NOT form
Re: Data Grid form search functionality (filtering)
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.
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
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 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
-
- Posts: 15
- Joined: Sat Mar 20, 2010 6:03 pm
Re: Data Grid form search functionality (filtering)
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
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)
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
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
-
- VIP Livecode Opensource Backer
- Posts: 7257
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Data Grid form search functionality (filtering)
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
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Posts: 15
- Joined: Sat Mar 20, 2010 6:03 pm
Re: Data Grid form search functionality (filtering)
Thank you Jacque,
That works just fine.
Much appreciated.
Mark
That works just fine.
Much appreciated.
Mark
-
- Posts: 15
- Joined: Sat Mar 20, 2010 6:03 pm
Re: Data Grid form search functionality (filtering)
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
You were right, it was fairly easy -- I'm still trying to get used to the syntax and framework...
Best wishes
Mark