Page 1 of 1

Fixing a search on a datagrid

Posted: Wed Aug 24, 2011 1:02 am
by melhiatt
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

Posted: Wed Aug 24, 2011 4:22 am
by dunbarx
Have you tried trapping the deletekey and backSpacekey messages?

What method are you using to work each keystroke?

Craig Newman

Re: Fixing a search on a datagrid

Posted: Wed Aug 24, 2011 4:58 am
by melhiatt
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

Re: Fixing a search on a datagrid

Posted: Wed Aug 24, 2011 11:24 pm
by dglass
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.

Re: Fixing a search on a datagrid

Posted: Thu Aug 25, 2011 1:09 am
by marksmithhfx
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?
Hi melhiatt,

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

Re: Fixing a search on a datagrid

Posted: Sat Aug 27, 2011 9:44 pm
by melhiatt
marksmithhfx wrote:
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?
Hi melhiatt,

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

Posted: Sun Aug 28, 2011 5:51 am
by dglass
Is the name of your datagrid "DataGrid"?