Page 1 of 1

DataGrid Search, Narrow search by Column

Posted: Fri Oct 30, 2020 7:02 pm
by pajito
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?

Re: DataGrid Search, Narrow search by Column

Posted: Fri Oct 30, 2020 7:51 pm
by Klaus
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

Re: DataGrid Search, Narrow search by Column

Posted: Fri Oct 30, 2020 8:25 pm
by pajito
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