Data Grid search box (long detailed explination)

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

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

Re: Data Grid search box (long detailed explination)

Post by marksmithhfx » Sat Dec 03, 2011 4:42 pm

gricha2380 wrote: Take a look. The table on the left is what I see just by opening the card. The table on the right is a duplicate table that is not tied into the search code.

img542.imageshack.us/img542/4213/screenshot20111202at102.png
Hi gricha2380, I've tried everyway I can think of to duplicate your problem. So far without any success. I've duplicated the datagrid (that just produces a non-responsive copy of the dg), I've removed all references to putting "empty" into the data grid, that didn't create the problem either (so my code to clear the dg seems unnecessary as well).

BTW, based on what I've learned here I went back and re-scripted it. The "else" clause is now just 1 line of LC

Code: Select all

on preopenstack
   put "/users/mark/runrev/summer academy" & "/sa index.txt" into tSavePath
   if there is a file tSavePath then
      -- copy the file into a variable
      put url ("file:" & tSavePath) into theData
      
      cleanupsaindex  -- go cleanup the index (you can read what that handler does but you won't need it)
          
      -- now initialize the datagrid (copy the variable into the dg)
      set the dgText of group "DataGrid" to theData
      set the cindex of this stack to theData  -- and save a copy in a custom property for later use
   else
      -- there is no file so initialize the dg using the custom property
      set the dgText of group "DataGrid" to the cindex of this stack
   end if
   put the number of lines of the cindex of this stack into thecount
   put thecount && "records" into fld "count"
end preopenstack
PS if you are still having problems, please post your "search" field code so we can check it. There may be something missing in there.

Cheers,
-- Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

gricha2380
Posts: 11
Joined: Thu Dec 01, 2011 8:53 pm
Contact:

Re: Data Grid search box (long detailed explination)

Post by gricha2380 » Sat Dec 03, 2011 6:49 pm

marksmithhfx wrote: PS if you are still having problems, please post your "search" field code so we can check it. There may be something missing in there.
The problem still persists. I've played around with the code some, but here is the what's currently in the Search field. I am experimenting with the code on two different cards, so I renamed the variables to avoid a conflict:

Code: Select all

on rawkeyup
   set the dgText of group "CustomerGrid" to empty
   put fld "search" into tsearchC
   put the uVirginText of group "CustomerGrid" into thecopyC
   filter thecopyC with "*" & tsearchC & "*"
   set the dgText [false] of group "CustomerGrid" to thecopyC
   put the number of lines in thecopyC into thecountC
   put thecountC && "Customer Records" into fld "count"
end rawkeyup
And here is the code currently in my Card Script (it was formerly in Stack Script):

Code: Select all

on preOpencard
   set the uVirginText of group "CustomerGrid" to the dgText of group "CustomerGrid"
end preOpencard

on closecard
   set the dgText of group "CustomerGrid" to empty
   set the dgText of group "CustomerGrid" to the uVirginText of group "CustomerGrid"
end closecard

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

Re: Data Grid search box (long detailed explination)

Post by marksmithhfx » Sat Dec 03, 2011 8:17 pm

gricha2380 wrote: The problem still persists. I've played around with the code some, but here is the what's currently in the Search field. I am experimenting with the code on two different cards, so I renamed the variables to avoid a conflict:
Hi, using your code and my SA data I was able to duplicate your problem immediately. But, I have no idea why (although I vaguely remember running into the same problem when I was developing the SA index).

The following appears to work:

1. Create a new datagrid, and create the column names as appropriate
2. In the datagrid create a custom property called uVirginText
3. Put a clean copy of your data into uVirginText
4. Modify the card script as follows:

Code: Select all

on preOpencard
   set the dgText of group "CustomerGrid" to the uVirginText of group "CustomerGrid"
   put the number of lines in the uVirginText of group "CustomerGrid" into thecountC
   put thecountC && "Customer Records" into fld "count"
end preOpencard
Delete the closecard handler. Leave your search code as is (or delete the first line, its not necessary). I tested this a bunch of times and it did not re-create the problem.

It is hard for me to comprehend where the problem might be (maybe Mark W has some ideas?). The two things we have changed are (a) we are not putting a copy of uVirginText into the datagrid when we close the card (because we don't have a closecard handler) and (2) we are not re-initializing the custom property when we open the card... we do that initialization only once, and in this case it was done manually by putting a copy of the data into uVirginText using the property inspector. However I don't really see why doing (a) or (b) should create a problem. But as I noted earlier, if I do those 2 things I can reproduce the problem immediately.

Let us know how it goes....

-- Mark
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

gricha2380
Posts: 11
Joined: Thu Dec 01, 2011 8:53 pm
Contact:

Re: Data Grid search box (long detailed explination)

Post by gricha2380 » Sat Dec 03, 2011 9:45 pm

Success!

The custom property worked perfectly. Thank you, Mark W and Mark S, for coming to my assistance in solving this problem. This has been a remarkably positive experience for me, and I am amazed at your level of expertise and friendliness. You are both superb ambassadors for the LiveCode community. I'd like very much to show you two the end result of this stack. I could not have done it with out your help.

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

Re: Data Grid search box (long detailed explination)

Post by marksmithhfx » Sat Dec 03, 2011 11:45 pm

gricha2380 wrote:Success!

The custom property worked perfectly. Thank you, Mark W and Mark S, for coming to my assistance in solving this problem. This has been a remarkably positive experience for me, and I am amazed at your level of expertise and friendliness. You are both superb ambassadors for the LiveCode community. I'd like very much to show you two the end result of this stack. I could not have done it with out your help.
Hey, glad to see you got it working... I know the feeling of satisfaction that brings. I've had plenty of help from the folks on the forums here, and in some respects feel like I have benefitted more than I can repay them. So it is nice to be able to lend a helping hand.

Be well,

-- Mark S
macOS 12.6.5 (Monterey), Xcode 14.2, LC 10.0.0, iOS 15.6.1
Targets: Mac, iOS

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Data Grid search box (long detailed explination)

Post by doobox » Thu Jun 12, 2014 4:19 am

I am currently implementing a search feature in a current project and my code may be of help to someone.
This code is based on a data grid form with 2 fields in each row template.
I search on the second field in each row.

You must handle the re-setting of your dgText appropriately, see here for more details on that : http://lessons.runrev.com/m/datagrid/l/ ... -with-data
Note this section of that linked lessons page :
"If you set the dgText property of a data grid form then the data will be imported but it is up to you to modify your Row Template Behavior to display the imported data correctly. If pFirstLineContainsHeaders is false then each item of each line in pText will be named "Label X" (where X is the item number) in the array that is passed to FillInData."

The code placed inside the search field :

Code: Select all

local tWorkingData, tVirginData, tSearch

on openField
   if tVirginData is empty then
      put the dgText of group "DataGrid 1" into tVirginData
   end if
end openField

on textChanged
   lock screen
   put tVirginData into tWorkingData
   put the text of field "search" into tSearch
   set the itemdelimiter to tab
   repeat for each line tline in tWorkingData
      if item 2 of tline begins with tSearch then
         put tline && cr after tFilteredData
      end if
   end repeat 
   set the dgText of group "DataGrid 1" to tFilteredData
   unlock screen
end textChanged 

on closeField
   if tSearch is empty then
      set the dgText of group "DataGrid 1" to tVirginData
      put empty into tVirginData
   end if
end closeField

on exitField
   if tSearch is empty then
      set the dgText of group "DataGrid 1" to tVirginData
      put empty into tVirginData
   end if
end exitField
Attachments
Search-Datagrid.livecode.zip
Search Datagrid Form Example
(6.5 KiB) Downloaded 156 times
Kind Regards
Gary

https://www.doobox.co.uk

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”