dgToolTip Snippet

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

dgToolTip Snippet

Mark Waddingham via use-livecode
Hi all.

If anyone is interested, I have a working version of a datagrid tooltip handler. It requires the arrayToText handler as written but that can be replaced by another function of your choosing that takes an array and returns some kind of text representation of it. (printKeys comes to mind but I'm not sure it would work well for a tooltip).

Put this code in your datagrid script:

--------
on mouseEnter
   put the long id of the target into tTarget
   -- replace the following key list with whatever datagrid column names you want in the tooltip
   -- if you exclude tKeyList it will include every column of the datagrid
   -- if you hold down the shift key when entering the datagrid it will also include every column of the datagrid
   put "customername,industry,salesperson,contactname,contactphone,contactemail" into tKeyList
   dgToolTip tTarget, tKeyList
end mouseEnter

on mouseLeave
   try
      set the tooltip of tTarget to empty
   end try
end mouseLeave
--------

Put this code in a backscript somewhere:

--------
on dgToolTip tTarget, tKeyList
      put the name of tTarget into tTargetName
     
      if tTargetName contains "HeaderLabel" or the first word of tTargetName is not "field" then
         exit dgToolTip
      end if
     
      replace quote with empty in tTargetName
      put the last word of tTargetName into tLine
      put the dgDataOfLine [tLine] of tTarget into aLineData
     
      if tKeyList is empty or the shiftKey is down then
         put the keys of aLineData into tKeyList
         sort lines of tKeyList ascending
         replace cr with comma in tKeyList
      end if
     
      repeat for each item tKey in tKeyList
         add 1 to tCounter
         put aLineData [tKey] into aRecordData [tCounter & ". " & tKey]
      end repeat
     
      put arrayToText(aRecordData, "record") into tText
      sort lines of tText numeric ascending by word 1 of each
     
      set the tooltip of tTarget to tText
end dgToolTip

function arrayToText aArrayData, pFormat, pStripRecordKeys
   if aArrayData is not an array then
      put "ERROR: Data passed is not an array!" into theValue
      return theValue
   end if
   
   if pStripRecordKeys is not in "true|false" then put false into pStripRecordKeys
   -- sort tArrayKeys ascending
   
   -- may be an array of values
   put the keys of aArrayData into tArrayKeys
   sort lines of tArrayKeys numeric ascending
   put line 1 of tArrayKeys is 0 into tHasHeader
   
   -- convert single array to numeric array of arrays
   if line 1 of tArrayKeys is not a number then
      put aArrayData into aTempArray [1]
      put aTempArray into aArrayData
      put the keys of aArrayData into tArrayKeys
   end if
   
   switch pFormat
      case "record"
         repeat for each line tArrayKey in tArrayKeys
            put aArrayData [tArrayKey] into aArrayRecord
            put the keys of aArrayRecord into tColumnKeys
           
            repeat for each line tColumnKey in tColumnKeys
               put tColumnKey & ": " & aArrayRecord [tColumnKey] & cr after tValue
            end repeat
         end repeat
         break
      case "table"
         -- table header
         if not tHasHeader then put cr into tValue
         
         repeat for each line tArrayKey in tArrayKeys
            add 1 to tCount
            put aArrayData [tArrayKey] into aArrayRecord
            put the keys of aArrayRecord into tColumnKeys
            sort lines of tColumnKeys numeric ascending
           
            repeat for each line tColumnKey in tColumnKeys
               if pStripRecordKeys and (char 1 of tColumnKey is "@") then next repeat
               
               if tCount = 1 and not tHasHeader then put tColumnKey & tab after line 1 of tValue
               put aArrayRecord [tColumnKey] & tab after tValue
            end repeat
           
            put cr into last char of tValue
         end repeat
         break
   end switch
   
   return tValue
end arrayToText
--------
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: dgToolTip Snippet

Mark Waddingham via use-livecode
Whoops! Also include in your datagrid script

local tTarget


> On Jul 12, 2017, at 15:04 , Bob Sneidar via use-livecode <[hidden email]> wrote:
>
> Put this code in your datagrid script:


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Loading...