DataGrid Search, Narrow search by Column

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
pajito
Posts: 30
Joined: Thu Apr 13, 2017 8:08 pm

DataGrid Search, Narrow search by Column

Post by pajito » Fri Oct 30, 2020 7:02 pm

Hi everybody ,

i am working on a project in which I want to include a search function. I found and used the following code in the forum

datagrid code

Code: Select all

command searchMe tString
   local tIndexList, tRecord, tHLIndexes
   put the dgIndexes of me into tIndexList
   repeat for each item tIndex in tIndexList
      put getDataOfIndex(tIndex) into tRecord
      repeat for each element tElement in tRecord
         if tElement contains tString then 
         put tIndex & comma after tHLIndexes
         exit repeat
         end if
      end repeat
   end repeat
   delete the last char of tHLIndexes
   set the dgHilitedIndexes of me to tHLIndexes
end searchMe
....and search button code

Code: Select all

on mouseUp
   local tSearchString
   ask "Search Term?" 
   if it is not empty then put it into tSearchString
   dispatch "searchMe" to group "DataGrid1" with tSearchString
end mouseUp

the problem is that I need to narrow down the search only in the first column named "NO" .
Any suggestions?

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

Re: DataGrid Search, Narrow search by Column

Post by Klaus » Fri Oct 30, 2020 7:51 pm

Hola Pajito,

this should do the trick:

Code: Select all

command searchMe tString
   local tIndexList, tRecord, tHLIndexes
   put the dgIndexes of me into tIndexList
   repeat for each item tIndex in tIndexList
      put the dgDataOfIndex[tIndex] of me into tRecord

     ## We only check this columns of each record:
      if tRecord["NO"] contains tString then
         put tIndex & comma after tHLIndexes
         exit repeat
      end if
   end repeat
   delete the last char of tHLIndexes
   set the dgHilitedIndexes of me to tHLIndexes
end searchMe
Out of my head, but should work!
(Famous last words :D )


Best

Klaus

pajito
Posts: 30
Joined: Thu Apr 13, 2017 8:08 pm

Re: DataGrid Search, Narrow search by Column

Post by pajito » Fri Oct 30, 2020 8:25 pm

Hi Klaus,

as you said (Famous last words) , from a famous guy in helping everyone.
Of course it works now, I will doublecheck it and I will come back.

Thank you so much

Klaus wrote:
Fri Oct 30, 2020 7:51 pm
Hola Pajito,

this should do the trick:

Code: Select all

command searchMe tString
   local tIndexList, tRecord, tHLIndexes
   put the dgIndexes of me into tIndexList
   repeat for each item tIndex in tIndexList
      put the dgDataOfIndex[tIndex] of me into tRecord

     ## We only check this columns of each record:
      if tRecord["NO"] contains tString then
         put tIndex & comma after tHLIndexes
         exit repeat
      end if
   end repeat
   delete the last char of tHLIndexes
   set the dgHilitedIndexes of me to tHLIndexes
end searchMe
Out of my head, but should work!
(Famous last words :D )


Best

Klaus

Post Reply