String search in a Datagrid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
String search in a Datagrid
How do I do a search on a datagrid from a keyed in string while having the DG only show the lines that have data that match the string? I see this type of functionality all over the place on my iPhone but I don’t know how to write the script. I have a DG with data in it. I have a field called search. The script I have used to do this in a list field doesn’t work. Any help would be much appreciated.
Thanks
Thanks
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
Re: String search in a Datagrid
Well, you could extract the data from the DG with the "dgText", run a search on the lines that match your search string in whatever way you want to do that, and then reload the DG with just that info. Probably prudent to store the original data in a custom property of the group so it can be restored later on.
Can you write a routine that will find all instances of your search string among what might be many lines with a match? Lots of ways to do this. Write back if you need more help.
Craig Newman
Can you write a routine that will find all instances of your search string among what might be many lines with a match? Lots of ways to do this. Write back if you need more help.
Craig Newman
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
Re: String search in a Datagrid
Hi Craig,
I'm new to DG so I'm not sure how to write this. Sorry.
I'm new to DG so I'm not sure how to write this. Sorry.
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
Re: String search in a Datagrid
Not your fault.
Any tab and return delimited data can be loaded directly in the clear via the "dgText", or if in an array via the "dgData" . These are both properties of the DG itself. You have to read the DataGrid manual, which takes some work, but is actually well written, and you only need to take from it what you need at this time. All it takes is time and effort.
But where are you asking for help? With loading or reading the data? With filtering based on the search string? Again, write back, but with more specific questions.
Craig Newman
Any tab and return delimited data can be loaded directly in the clear via the "dgText", or if in an array via the "dgData" . These are both properties of the DG itself. You have to read the DataGrid manual, which takes some work, but is actually well written, and you only need to take from it what you need at this time. All it takes is time and effort.
But where are you asking for help? With loading or reading the data? With filtering based on the search string? Again, write back, but with more specific questions.
Craig Newman
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
Re: String search in a Datagrid
Hi Craig,
I think I can figure out how to get the data into the DG by building arrays. I could use help dong the search and then filtering based upon the search string. I do this type of search in a number of places in my desktop apps but I would like to switch over to using datagrid instead of fields. Any help pointing me in the right direction would be very much appreciated.
Thanks,
Tom
I think I can figure out how to get the data into the DG by building arrays. I could use help dong the search and then filtering based upon the search string. I do this type of search in a number of places in my desktop apps but I would like to switch over to using datagrid instead of fields. Any help pointing me in the right direction would be very much appreciated.
Thanks,
Tom
dunbarx wrote:Not your fault.
Any tab and return delimited data can be loaded directly in the clear via the "dgText", or if in an array via the "dgData" . These are both properties of the DG itself. You have to read the DataGrid manual, which takes some work, but is actually well written, and you only need to take from it what you need at this time. All it takes is time and effort.
But where are you asking for help? With loading or reading the data? With filtering based on the search string? Again, write back, but with more specific questions.
Craig Newman
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
Re: String search in a Datagrid
Hi Tom,
how do you search in a "normal" listfield?
Do something like this:
1. When you "fill" your datagrid the first time (openstack or opencard) with data you should store the complete data -> the dgtext of grp xyz in a variable or custom property!
I use this in my example: -> the cCompleteDGData of THIS stack
Since we will filter (-> reduce) the data for the search, we will always use the complete data as a base for our search!
2. In the search field script (on keyup?) put the content of the search field into a variable and filter the dgtext of the datagrid:
And don't forget a "reset" button that will load the complete original data back into your datagrid if neccessary:
...
set the dgtext of grp "Your datagrid here" to the cCompleteDGData of THIS stack
...
Hint: DGTEXT will only work with datagrid of type TABLE!
Hope this helps!
Best
Klaus
how do you search in a "normal" listfield?
Do something like this:
1. When you "fill" your datagrid the first time (openstack or opencard) with data you should store the complete data -> the dgtext of grp xyz in a variable or custom property!
I use this in my example: -> the cCompleteDGData of THIS stack
Since we will filter (-> reduce) the data for the search, we will always use the complete data as a base for our search!
2. In the search field script (on keyup?) put the content of the search field into a variable and filter the dgtext of the datagrid:
Code: Select all
...
## Search field script
put me into tSearchString
put the cCompleteDGData of THIS stack into tData
## Now we FILTER this data and add wildcards to the serach, so we will also find something
## that is somewhere in the middle of the datagrid, know what I mean?:
filter tData with ("*" & tSearchString & "*")
## Nothiong found_
if tData = emtpy then
beep
exit to top
end if
## We found something, so lets display the results:
set the dgdata of grp "Your datagrid here" to tData
...
...
set the dgtext of grp "Your datagrid here" to the cCompleteDGData of THIS stack
...
Hint: DGTEXT will only work with datagrid of type TABLE!
Hope this helps!
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: String search in a Datagrid
Nice code Klaus!
I've never messed with datagrids in any meaningful way but am tempted and the search capability would make it much nicer ...
However does tData as in:
contain a complete dg row? and how about headers?
Dave
I've never messed with datagrids in any meaningful way but am tempted and the search capability would make it much nicer ...
However does tData as in:
Code: Select all
filter tData with ("*" & tSearchString & "*")
Dave
"...this is not the code you are looking for..."
Re: String search in a Datagrid
Hi Dave,
in my example tData is the COMPLETE data of the datagrid: One line = One row
Headers?
I do not see headers as part of the actual data, and they are NOT part of the DGTEXT of a datagrid,
at least not when you retrieve the dgtext.
Best
Klaus
in my example tData is the COMPLETE data of the datagrid: One line = One row
Headers?
I do not see headers as part of the actual data, and they are NOT part of the DGTEXT of a datagrid,
at least not when you retrieve the dgtext.
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 858
- Joined: Wed Jun 24, 2009 1:17 pm
- Contact:
Re: String search in a Datagrid
Smashing - thanks Klaus
"...this is not the code you are looking for..."