Search in Data Grid Form

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
keram
Posts: 340
Joined: Fri Nov 08, 2013 4:22 am

Search in Data Grid Form

Post by keram » Tue Mar 04, 2014 3:27 am

Hello,

I'd like to do a search in a data grid form but exclude the hilite state of checkboxes.
Here are the steps:
put the dgText of grp "DataGrid 1" into tData
then
filter tData with ("*" & tSearchString & "*")

but in the tData there will be "true" or "false" for the hilite state of checkboxes.
If I want to search the text lines for words like true or false etc. then the lines that have the checkbox hilites as true or false will also be found and displayed.

How can I eliminate in a simplest way the checkbox hilites values from the filter?
Attached is the stack as an example.

Thanks in advance.

keram
Attachments
DG Form search.zip
(17.44 KiB) Downloaded 208 times
Using the latest stable version of LC Community 6.7.x on Win 7 Home Premium, 64bit

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

Re: Search in Data Grid Form

Post by Klaus » Tue Mar 04, 2014 12:14 pm

Hi keram,

OK, first use the FILTER WITH command for a rough check.
Then you will need to loop through all lines and all items of the lines that you want to check.
Means leave out the column(s) with the hilite values.

Know what I mean?
No quick way :D


Best

Klaus

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

Re: Search in Data Grid Form

Post by keram » Tue Mar 04, 2014 4:36 pm

Thanks Klaus,

If I understood correctly this would be the solution:

Code: Select all

on mouseUp
   local tSearchString,Counter = "0", DataArray
   set itemDel to tab
   
   ask "Search for what word or string of words?" with "tellus" titled "Search"
   if it = empty then exit to top
   put it into tSearchString
   
   put the dgText of grp "DataGrid 1" into tData
   
   filter  tData with ("*" & tSearchString & "*") 
   
   repeat for each line i in tData
      filter item 3 of i  with ("*" & tSearchString & "*")  --  I want to search only in item 3 of each line 
   end repeat
   
   if tData = empty then
      answer "No matching data!"
      exit to top
   end if
    
   lock screen
   repeat for each line i in tData
      add 1 to Counter
      put item 4 of i into DataArray[Counter]["Num"]  --line 1 number of dgform
      put item 1 of i into DataArray[Counter]["BtnCheck"]  --line 1 checkbox of dgform
      put item 2 of i into DataArray[Counter]["Cat"]  --line 1 cat of dgform
      put item 3 of i into DataArray[Counter]["Label"]  --line 1 label of dgform
   end repeat
   
   
   set the dgData of grp "DataGrid 1" to DataArray  --populate dgform
   set the dgVScroll of grp "DataGrid 1" to "0"  --top
   send "RefreshList" to grp "DataGrid 1"
   
end mouseUp
   
this is what I added:
filter tData with ("*" & tSearchString & "*")

repeat for each line i in tData
filter item 3 of i with ("*" & tSearchString & "*") -- I want to search only in item 3 of each line
end repeat

but still when I search for false or true, the search is not ignoring the columns with hilite values.

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

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

Re: Search in Data Grid Form

Post by Klaus » Tue Mar 04, 2014 5:04 pm

Hi Keram,

you cannot filter ITEMS in a line unfortunately!

I was thinking of something like this:

Code: Select all

on mouseUp
  local tSearchString,Counter = "0", DataArray
  set itemDel to tab
  ask "Search for what word or string of words?" with "tellus" titled "Search"
  if it = empty then
    exit to top
  end if
  put it into tSearchString
  put the dgText of grp "DataGrid 1" into tData
  filter  tData with ("*" & tSearchString & "*")
  
  ## No need to continue if the rough check already fails!
   if tData = empty then
    answer "No matching data!"
    exit to top
  end if
  
  repeat for each line i in tData
    if item 3 of i contains tSearchString then
      put i & CR after tNewData
    end if
  end repeat
  delete char -1 of tNewData
     
  ## Nothing found
  if tNewData = empty then
    answer "No matching data!"
    exit to top
  end if
     
  ## Since your datagrid ia obviously a TABLE you can simply: 
  set the dgTEXT of grp "DataGrid 1" to tNewData  --populate dgform
  set the dgVScroll of grp "DataGrid 1" to "0"  --top
  send "RefreshList" to grp "DataGrid 1"    
end mouseUp
Best

Klaus

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

Re: Search in Data Grid Form

Post by keram » Tue Mar 04, 2014 5:47 pm

Hi Klaus,

It works OK now.
This is a dg FORM so the last few lines I have to keep as they were before:
lock screen
repeat for each line i in tNewData
add 1 to Counter
put item 4 of i into DataArray[Counter]["Num"] --line 1 number of dgform
put item 1 of i into DataArray[Counter]["BtnCheck"] --line 1 checkbox of dgform
put item 2 of i into DataArray[Counter]["Cat"] --line 1 cat of dgform
put item 3 of i into DataArray[Counter]["Label"] --line 1 label of dgform
end repeat

set the dgData of grp "DataGrid 1" to DataArray --populate dgform


Thanks again :)

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

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

Re: Search in Data Grid Form

Post by Klaus » Tue Mar 04, 2014 5:50 pm

Hi Keram,
keram wrote:This is a dg FORM
ah, OK, I guessed TABLE from your first lines:
...
put the dgText of grp "DataGrid 1" into tData
filter tData with ("*" & tSearchString & "*")
...
:D

Best

Klaus

Post Reply