[flexcoders] Search while you type?

2005-09-29 Thread Greg Johnson
I return a list from a database into a datagrid.  I then have a text 
entry field with a keydown event set to call a function.
The function runs though the currently loaded like, compares what is in 
the text entry field's .text property and creates a array with only 
those entries then resets the dataprovider parameter of the datagrid to 
the filtered list.  Here is the code

private function filterlist() {
var TempObject:Object = new Object();
var RunningArray:Array = new Array();
for(var i=0; i  OTD_TECH_RESULTS.dataProvider.length; i++){
 TempObject = OTD_TECH_RESULTS.dataProvider[i];
 if ( TempObject.INTERNAL_CASE_NUMBER.indexOf(search.text)) {
 RunningArray.push(TempObject);
}
}
OTD_TECH_RESULTS.dataProvider = RunningArray;
OTD_TECH_RESULTS.dataProvider.dispatchEvent({type: modelChanged});
}

INTERNAL_CASE_NUMBER is one of the columns

What happens is that it gives me no entries once I type the first 
character, and even when I got it to return results it wouldn't seem to 
update once I hit a second key unless I hit backspace first.

I am using indexOf because I couldn't find a find command anywhere.

Any ideas how I can make this work?

-- 
Greg Johnson
Owner  Lead Technician
[EMAIL PROTECTED]

Techno-Fix-It
Filling the Gap Between the Store and the Repair Shop
--
www.technofixit.com
Phone:(919)-371-1476
Fax:(919)-882-9804
P.O. Box 1094
Morrisville, N.C. 27560



 Yahoo! Groups Sponsor ~-- 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/nhFolB/TM
~- 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

* To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/

* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]

* Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
 




Re: [flexcoders] Search while you type?

2005-09-29 Thread Greg Johnson






I did some sniffin around and got mine to work right. For anyone
interested I made a kinda generic version below.

// sourceArray = any array
you are currently using as a datasource, most likely it will be
preloaded with entries
// search = the ID of the text entry field you want to use while typing
private function
filterlist() {
 var TempObject:Object = new Object(); // This will hold a source
structure
 var RunningArray:Array = new Array(); // This will become the new
dataSource for the datagrid
 var compString:String = new String(); // This will have just the
element of the TempObject you want to test
 // Start Looping over the original datasource
 for(var i=0; i  sourceArray.length; i++){
 TempObject = sourceArray[i]; // Assign the current
source row structure to the TempObject
 compString = TempObject.TITLE; // Assign the comp(are)String to
the Element you want to filter on
 // check of the text property of most likly a text field, if it is
in the compString
 if ( compString.indexOf(String(search.text)) = 0 ) {
  RunningArray.push(TempObject); //If it is a match, add the row
from the source to the filtered array
  }
 }
 destinationDataGrid.dataProvider = RunningArray; // Rebind the
DataGrid to the new filtered array
 destinationDataGrid.dataProvider.dispatchEvent({type:
"modelChanged"}); // Dont know if this is needed, may work without.
}

No wildcards or anything like that are needed, esentialy its
just like searching with the astrix wild character on each end of
whatever you type. Its pretty fast since the data is already loaded
into memeory

Hope this helps someone







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com








  
  
SPONSORED LINKS
  
  
  

Web site design development
  
  
Computer software development
  
  
Software design and development
  
  


Macromedia flex
  
  
Software development best practice
  

   
  







  
  
  YAHOO! GROUPS LINKS



  Visit your group "flexcoders" on the web.
  To unsubscribe from this group, send an email to:[EMAIL PROTECTED]
  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.