Fixing a search on a datagrid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Fixing a search on a datagrid
I have a datagrid and I have a field that you can type in to filter the info in the datagrid as you type. This works fine, but I want it to work in reverse as well. If you have something typed in the search field and you backspace, I want it to fill back in the datagrid. Any ideas?
Re: Fixing a search on a datagrid
Have you tried trapping the deletekey and backSpacekey messages?
What method are you using to work each keystroke?
Craig Newman
What method are you using to work each keystroke?
Craig Newman
Re: Fixing a search on a datagrid
This is my current code, someone helped me with it and they built in code for the deleting and backspacing, but that part doesn't work:
on rawKeyUp pKeyCode
--answer pKeyCode
switch pKeyCode
--if the user uses the backspace or delete key then the contents of the search field
--will change, and we need to filter the entire list on the new contents
--so we will put the full list back, and then filter
case 65288 --backspace
case 65535 --delete
lock screen
break
end switch
if field "First" is empty then
else
--this filter is <<anything wildcard>>filter term<<anything wildcard>>tab<<anything wildcard>>
--the tab<<anything wildcard>> is to ensure it only looks in the first 'column' and returns results regardless of
--what's in the second 'column' (follows the tab character
filter field "info" with "*" & field "First" & "*"& tab & "*"
end if
unlock screen
pass rawKeyUp
end rawKeyUp
on rawKeyUp pKeyCode
--answer pKeyCode
switch pKeyCode
--if the user uses the backspace or delete key then the contents of the search field
--will change, and we need to filter the entire list on the new contents
--so we will put the full list back, and then filter
case 65288 --backspace
case 65535 --delete
lock screen
break
end switch
if field "First" is empty then
else
--this filter is <<anything wildcard>>filter term<<anything wildcard>>tab<<anything wildcard>>
--the tab<<anything wildcard>> is to ensure it only looks in the first 'column' and returns results regardless of
--what's in the second 'column' (follows the tab character
filter field "info" with "*" & field "First" & "*"& tab & "*"
end if
unlock screen
pass rawKeyUp
end rawKeyUp
Re: Fixing a search on a datagrid
Most likely it doesn't work because it was written for your original need: using a table field.
You are now using a datagrid, and so have to change how you do the filtering.
You are now using a datagrid, and so have to change how you do the filtering.
-
- VIP Livecode Opensource Backer
- Posts: 931
- Joined: Thu Nov 13, 2008 6:48 am
Re: Fixing a search on a datagrid
Hi melhiatt,melhiatt wrote:I have a datagrid and I have a field that you can type in to filter the info in the datagrid as you type. This works fine, but I want it to work in reverse as well. If you have something typed in the search field and you backspace, I want it to fill back in the datagrid. Any ideas?
This might help (look for the 'Summer Academy Index' in the online User Samples.... it is really nothing more than 1 datagrid and 1 search field and will give you a good idea of how this works... the following is copied from the search field):
1st, put your dgText into a custom property (here I call it cindex)
on rawkeyup
put fld "search" into tsearch
put the cindex of this stack into thecopy -- copy the custom property into a variable
#### next 3 lines are the same that bangkok posted to you in another topic ####
filter thecopy with "*" & tsearch & "*"
put false into firstLineContainsColumnNames -- because your filtering probably removed them
set the dgText [ firstLineContainsColumnNames ] of group "DataGrid" to thecopy
end rawkeyup
on returninfield
-- just ignore it
end returninfield
Since you are always "filtering" the original data (from cindex), as you back keys out of the search field it will display more entries.
Hope it helps.
-- Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS
Targets: Mac, iOS
Re: Fixing a search on a datagrid
marksmithhfx wrote:Hi melhiatt,melhiatt wrote:I have a datagrid and I have a field that you can type in to filter the info in the datagrid as you type. This works fine, but I want it to work in reverse as well. If you have something typed in the search field and you backspace, I want it to fill back in the datagrid. Any ideas?
This might help (look for the 'Summer Academy Index' in the online User Samples.... it is really nothing more than 1 datagrid and 1 search field and will give you a good idea of how this works... the following is copied from the search field):
1st, put your dgText into a custom property (here I call it cindex)
on rawkeyup
put fld "search" into tsearch
put the cindex of this stack into thecopy -- copy the custom property into a variable
#### next 3 lines are the same that bangkok posted to you in another topic ####
filter thecopy with "*" & tsearch & "*"
put false into firstLineContainsColumnNames -- because your filtering probably removed them
set the dgText [ firstLineContainsColumnNames ] of group "DataGrid" to thecopy
end rawkeyup
on returninfield
-- just ignore it
end returninfield
Since you are always "filtering" the original data (from cindex), as you back keys out of the search field it will display more entries.
Hope it helps.
-- Mark
Thanks Mark, I used your code, but get an error on line 7
set the dgText [ firstLineContainsColumnNames ] of group "DataGrid" to thecopy
Re: Fixing a search on a datagrid
Is the name of your datagrid "DataGrid"?