Fixing a search on a datagrid

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
melhiatt
Posts: 68
Joined: Wed May 25, 2011 9:17 am

Fixing a search on a datagrid

Post by melhiatt » Wed Aug 24, 2011 1:02 am

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?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Fixing a search on a datagrid

Post by dunbarx » Wed Aug 24, 2011 4:22 am

Have you tried trapping the deletekey and backSpacekey messages?

What method are you using to work each keystroke?

Craig Newman

melhiatt
Posts: 68
Joined: Wed May 25, 2011 9:17 am

Re: Fixing a search on a datagrid

Post by melhiatt » Wed Aug 24, 2011 4:58 am

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

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: Fixing a search on a datagrid

Post by dglass » Wed Aug 24, 2011 11:24 pm

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.

marksmithhfx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 931
Joined: Thu Nov 13, 2008 6:48 am

Re: Fixing a search on a datagrid

Post by marksmithhfx » Thu Aug 25, 2011 1:09 am

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
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

melhiatt
Posts: 68
Joined: Wed May 25, 2011 9:17 am

Re: Fixing a search on a datagrid

Post by melhiatt » Sat Aug 27, 2011 9:44 pm

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

dglass
Posts: 519
Joined: Thu Sep 24, 2009 9:10 pm
Contact:

Re: Fixing a search on a datagrid

Post by dglass » Sun Aug 28, 2011 5:51 am

Is the name of your datagrid "DataGrid"?

Post Reply