Searching 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
altamative131
Posts: 7
Joined: Mon Jan 13, 2014 6:57 pm

Searching a Datagrid

Post by altamative131 » Fri Jan 24, 2014 5:01 pm

Hello LiveCode pimps!!!


I have an issue that I am trying to figure out a solution to...and I require your assistance if you would be so kind.

I have 2 datagrids. One datagrid contains all of my saved data, the second is going to be to display searched data from the first one. My question is, how in the heck do I go about doing that?

The datagrid with all of my information is going to be on a "hidden" card and the display datagrid will be on a public "reporting" card.

my question is how do I search for a specific string on the first datagrid, and have it display the entire line that string is on and all instances of that string.

Any help would be much appreciated.

Thanks!

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Searching a Datagrid

Post by Klaus » Fri Jan 24, 2014 5:14 pm

HI altamative131,

if your datagrid is of type TABLE, you could do something like this:

Code: Select all

...
put "whatever" into tSearchString

## Now put all data into a variable:
put the dgtext of grp "the hidden one with all your data in it" of cd "a card with a hidden datagrid" into tData

## Now use FILTER to get all lines with the searchstring in them:
filter tData with ("*" & tSearchString & "*")
if tData = empty then
  answer "No matching data!"
  exit to top
end if

## Finally put found data into other datagrid
set the dgdata of grp "data display" to tData
...
You get the picture 8)


Best

Klaus

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

Re: Searching a Datagrid

Post by dunbarx » Fri Jan 24, 2014 6:12 pm

Pimps?

Craig

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Searching a Datagrid

Post by Klaus » Fri Jan 24, 2014 6:17 pm

LCpimp.jpg
LCpimp.jpg (31.03 KiB) Viewed 6554 times
dunbarx wrote:Pimps?
Craig
Yep, that's me! :D

LC4iOS
Posts: 88
Joined: Tue Dec 03, 2013 8:15 pm

Re: Searching a Datagrid

Post by LC4iOS » Fri Jan 24, 2014 10:31 pm

Klaus wrote:HI altamative131,

if your datagrid is of type TABLE, you could do something like this:

Code: Select all

...
put "whatever" into tSearchString

## Now put all data into a variable:
put the dgtext of grp "the hidden one with all your data in it" of cd "a card with a hidden datagrid" into tData

## Now use FILTER to get all lines with the searchstring in them:
filter tData with ("*" & tSearchString & "*")
if tData = empty then
  answer "No matching data!"
  exit to top
end if

## Finally put found data into other datagrid
set the dgdata of grp "data display" to tData
...
You get the picture 8)


Best

Klaus
Nice Klaus.
Many thanks.
Last edited by LC4iOS on Fri Jan 24, 2014 10:37 pm, edited 1 time in total.
Thanks to RunRev.
Thanks to LiveCode forum members.

LiveCode v5.5.5 - iOS Android Mac Windows - 6.5 Community
27" 2012 iMac i5, MacBook Pro, MacBook Air, iPhone 5, iPhone 4
xCode 5.0.2 - iOS7 - OS X Mavericks
Paid Apple iOS Developer Program Member

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Searching a Datagrid

Post by Klaus » Fri Jan 24, 2014 10:35 pm

LC4iOS wrote:Nice Claus.
Klaus, with a K! 8)

Don't mess with a PIMP! :D

keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Re: Searching a Datagrid

Post by keram » Sat Mar 01, 2014 4:38 am

Hi Klaus with K, :)
Klaus wrote:if your datagrid is of type TABLE, you could do something like this:
Is this working only for dg Tables or for dg Forms as well?

Nice photo of you... :wink:
or maybe photo on this page
http://newsletters.livecode.com/october ... etter3.php
is better ... is it you?

keram
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

blairetabay
Posts: 34
Joined: Mon Feb 24, 2014 10:12 am

Re: Searching a Datagrid

Post by blairetabay » Sat Mar 01, 2014 10:02 am

altamative131,

this work for me.

i am using a datagrid and a database to show the exact value is been search put this code in you button to search

it only work if you have a database.

Code: Select all

 local Ldisplay
      
      local Tdisplay, sea
      
      put field "txt_keywords" into search
      
        
      put  "select id, lastName,givenName,middleName,age,sex from hos_tblpatientinfo where lastName LIKE '%" & search & "%'" into tabay
      put revdatafromQuery(,,connID,tabay)into Tdisplay
      set the dgText of group "dgGrid" to tDisplay

best

blaireTabay

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Searching a Datagrid

Post by Klaus » Sat Mar 01, 2014 12:17 pm

Hi Blaire,

yes, this is how one searches a database, but the original poster had been asking for something else! 8)


Best

Klaus

Post Reply