how interact if the user makes changes in a text field

Robert Sneidar slylabs13 at me.com
Sat Nov 24 15:09:31 EST 2012


This is what I do. Obviously, when you read the code, I am interacting with a database connection, so you will have to write your own code. It's still buggy because I was rewriting it to not read from the database every time, but the keyUp handler works perfectly. It will basically wait until a delay has elapsed before filtering the datagrid, so it is very responsive. 

Bob

local lSavedData, lSavedID

--> all handlers

on rawKeyUp
   if the text of me is not empty then
      show button "btnCloseFind"
      put the ticks into theLastTime
      wait .75 seconds with messages
      filterDataGrid
   else
      put empty into gStartTime
      hide button "btnCloseFind"
      if lSavedData is an array then 
         set the dgData of group "dgTableData" to lSavedData
         put empty into lSavedData
      end if
      exit to top
   end if
   pass rawKeyUp
end rawKeyUp

on filterDataGrid
   -- Get the value
   put the text of me into theValue
    
   -- save the selection
   put the dgHilitedIndex of group "dgTableData" into theIndex
   put the dgDataOfIndex[theIndex] of group "dgTableData" into theRowA
   put theRowA["uniqueid"] into lSavedID
    
   -- Save the datagrid data
   if not (lSavedData is an array) then
      put the dgData of group "dgTableData" into theDataA
      put theDataA into lSavedData
   else
      put lSavedData into theDataA
   end if
    
   -- Get a list of visible columns
   put the dgProps["columns"] of group "dgTableData" into theColumns
   
   -- convert the datagrid array to key text
   put altPrintKeys(theDataA) into theText
    
   -- filter the data
   filter theText with "*" & tab & theValue & "*"
    
   -- convert the text back to an array
   put altKeysToArray(theText) into theDataA
    
   set the dgData of group "dgTableData" to theDataA
   hiliteRecord
    
   dispatch "selectionChanged" to group "dgTableData"
   -- set the dgFocus of group "dgTableData" to true
end filterDataGrid

on restoreDataGrid
    put empty into field "FindBar"
    set the dgData of group "dgTableData" to lSavedData
    hiliteRecord
    set the dgFocus of group "dgTableData" to true
    put empty into lSavedData
    put empty into lSavedID
end restoreDataGrid

on hiliteRecord
    dispatch findIndex to group "dgTableData" with "uniqueid", lSavedID
    put the result into theFoundIndex
    
    if theFoundIndex = 0 then
         set the dgHilitedLine of group "dgTableData" to 1
    else
         set the dgHilitedIndex of group "dgTableData" to theFoundIndex
    end if
end hiliteRecord
On Nov 24, 2012, at 4:27 AM, Ueliweb wrote:

> I want to implement a "live search" so if the user enter new letter in a
> search field.
> The DataGrid should show only the entries that contains the letters in one
> or more column.
> 
> I could not find a message or function yet ...
> 
> Is there any message sent?
> Other suggsestion?
> 
> thanks
> Ueliweb
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list