Typeahead / Filter Datagrid based on a search string

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
mrk
Posts: 21
Joined: Mon Apr 03, 2017 6:16 am
Location: Perth, Western Australia

Typeahead / Filter Datagrid based on a search string

Post by mrk » Wed Aug 16, 2017 4:43 pm

Hi All

Firstly the code below is my attempt at combining a couple of different threads about this particular issue. I hope by posting this it will help others.
Thanks to: zaxos, sritcp,billworld, Janschenkel and bn for their posts which guided me to the below "solution"

Basically I have a datagrid with two columns. I want the user to be able to search by the first column (EqipmentCode) by typing the search into a field (fEquipSearch).
I did away with the timer resetting the buffer as I know some of the users (including myself) would end up getting strange results as they can get distracted.
I have a problem where the "EquipmentDescription" column isn't being populated on the result of the search, but I'm sure I'll get it figured out (any help would be appreciated).

Code: Select all


local sBuffer, sTimer

on keyup pKey
   put the milliseconds into sTimer
   --send "clearBuffer" to me in 1000 milliseconds
   put pKey after sBuffer
   StartSearch
end keyup


on backspaceKey
   delete char -1 of sBuffer
      delete char -1 of field fEquipSearch
   StartSearch
end backspaceKey

on StartSearch
  PopulateEquipDG
  lock screen
  put sBuffer into vSearch
  put the dgdata of group "DataGrid2" into vTable1
  put the dgIndexes of group "DataGrid2" into vIndex1
   
   if vSearch <> "" then -- added this because if its not there and the user has deleted the text string, the datagrid redraws with no data.
   
   repeat for each item iIndex in vIndex1
      if vTable1[iIndex]["EquipmentCode"] contains vSearch then
         put vTable1[iIndex]["EquipmentCode"] after vTable2[iIndex]["EquipmentCode"]
         put vTable1[iIndex]["EquipmentDescription"] after vTable2[iIndex]["EquipmentDescription"]
         end if
   end repeat 
   set the dgdata of group "DataGrid2" to vTable2
   unlock screen
end if
end StartSearch

on ClearBuffer
  -- -- adjust for typing speed
   -- -- after 1000 milliseconds the buffer is cleared and you can type for a new selection
   -- if the milliseconds - sTimer > 5000  then
   put "" into sBuffer
   PopulateEquipDG
    --else 
     --   send "clearBuffer" to me in 1000 milliseconds
    --end if
end ClearBuffer
Last edited by mrk on Fri Aug 18, 2017 5:29 am, edited 1 time in total.

mrk
Posts: 21
Joined: Mon Apr 03, 2017 6:16 am
Location: Perth, Western Australia

Re: Typeahead / Filter Datagrid based on a search string

Post by mrk » Fri Aug 18, 2017 5:29 am

Found the problem...typo. I've fixed the code above

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”