Searching for partial matches in a datagrid
    zryip theSlug 
    zryip.theslug at gmail.com
       
    Wed Aug 10 15:28:00 EDT 2011
    
    
  
Hi Bob,
Maybe time for sharing some hidden scripts.
Here is a part of the DGH engine script that could probably do the trick:
command dgh_FindLine pWhichDataGrid, pKeyIndexA, pSearchType, pSearchString
  local tTheIndexList, tIndex, tTheLineList
  _dgh_FindIndex pWhichDataGrid, pKeyIndexA, pSearchType, pSearchString
  put the result into tTheIndexList
  repeat for each item tIndex in tTheIndexList
     put the dgLineOfIndex[tIndex] of pWhichDataGrid into item (the
number of items of tTheLineList + 1) of tTheLineList
  end repeat
  if (tTheLineList is empty) then
     return 0
  else
     return tTheLineList
  end if
end dgh_FindLine
private command _dgh_FindIndex
pWhichDataGrid,pTpKeyIndexA,pSearchType,pSearchString
  local foundAMatch, theFoundIndex, i, theIndex, tIndexValue,
tSearchType, tNotSearch, tSearchString, tError
  if (pSearchType is among the items of _zuSearchContentOperatorList()) then
     try
        put the dgData of pWhichDataGrid into sDataArray
        repeat for each key theIndex in sDataArray
           repeat with i = 2 to the paramCount step 3
              put sDataArray[theIndex][param(i)] into tIndexValue
              put param(i+1) into tSearchType
              put param(i+2) into tSearchString
              if (first word of tSearchType is "not") then
                 put "not " into tNotSearch
                 delete first word of tSearchType
              else
                 put empty into tNotSearch
              end if
              put value(tNotSearch & "(" & quote & tIndexValue &
quote && tSearchType && quote & tSearchString & quote & ")") into
foundAMatch
              exit repeat
           end repeat
           if foundAMatch then
              put theIndex into item (number of items of
theFoundIndex + 1) of theFoundIndex
           end if
        end repeat
        if (theFoundIndex is empty) then
           return 0
        else
           return theFoundIndex
        end if
     catch tError
        answer tError
     end try
  else
     answer pSearchType && "is not in" && _zuSearchContentOperatorList())
  end if
end _dgh_FindIndex
private function _zuSearchContentOperatorList
  return "is,begins with,ends with,contains,is not,not begins
with,not ends with,not contains,=,>,>=,<,<=,<>"
end _zuSearchContentOperatorList
It is an implementation of the FindIndex and FindLine handler of the
Datagrid library with additional capabilities. The capacity of
searching with multiple queries is removed. I'm using another couple
of handlers for doing that.
Note that all the existing operators can be use: contains, begins
with, ends with, >, <, =, is, etc
Usage examples:
put the long id of grp "myDataGrid" into tDataGridRef
dgh_FindLine tDataGridRef, "Col1", "contains", "a"
put the result into tTheLineFound
set the dgHilitedLines of tDataGridRef to tTheLineFound
On Wed, Aug 10, 2011 at 12:43 AM, Bob Sneidar <bobs at twft.com> wrote:
> Hi all.
>
> I am hoping there will be a way to search a datagrid for PARTIAL matches. I already can find EXACT matches, and I tried regex on the findIndex command, to no avail. I know that if I cannot I can always get the dgText of the datagrid, but there is a problem with that method. First, the datagrid may contain a huge amount of data, and it seems inefficient to work with strings if I can use arrays instead. Second, if I need to set the dgText of the datagrid to what I find, it will wipe all my hidden data columns, that is array keys which I do not have a column for in the datagrid. I depend on these.
>
> So I can kludge a way to do this, but I was hoping I was simply missing something.
Best Regards,
-- 
-Zryip TheSlug- wish you the best! 8)
http://www.aslugontheroad.co.cc
    
    
More information about the use-livecode
mailing list