Copy link to clipboard
Copied
Hello all. I am loading a csv file into a datagrid. Is there a way to setup a text input to search and display the desired results?
For ex. I have a long list of addresses which is the csv file that is being loaded into the data grid. I want to be able to search for zip codes and only display those addresses with that zip code.
Thanks for any help.
you call the zipF and pass the zip code (as a string). zipF returns a dataprovider of matching zip codes. each object contains all the data you showed was in your csv file.
if your input textfield is input_tf, you could use:
somebtn.addEventListener(MouseEvent.CLICK,searchF);
function searchF(e:MouseEvent):void{
// i assume you want to display this in datagrid, eg dg
dg.dataProvider=zipF(input_tf.text);
}
Copy link to clipboard
Copied
yes, but exactly how you do that depends on your csv file structure and possibly on how you parse that file with as3.
without knowing that info, there's a fair chance the indexOf() method of strings and of arrays would be helpful.
Copy link to clipboard
Copied
Would it help to show you how Im pulling in the csv file?
Copy link to clipboard
Copied
i assume you're using a urlloader and the more relevant issue is the structure of the csv file
Copy link to clipboard
Copied
The CSV is a simple 5 column spreadsheet with a few hundred entries (addresses).
Business, Name, address, city, state, zip .
But I need to search by zip.
Text input search, and only display those addresses with searched zip in the same datagrid.
Copy link to clipboard
Copied
are you splitting the loaded string on carriage return and then on comma to create an array?
Copy link to clipboard
Copied
Here is the as3 Im using.
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE,completeF);
urlLoader.load(new URLRequest("cust-list-delim.csv"));
var dg:DataGrid
function completeF(e:Event):void{
var dataS:String = e.target.data;
var dataA:Array = dataS.split("\n").join("").split("\r");
var dpA:Array = [];
var itemA:Array;
for(var i:int=0;i<dataA.length;i++){
itemA = dataA.split(",");
dpA.push({"Business":itemA[1],"Name":itemA[2],"Address":itemA[3],"City":itemA[4],"State":itemA[5],"Zip":itemA[6]});
}
var dp:DataProvider = new DataProvider(dpA);
dg.columns = ["Business","Name","Address","City","State","Zip"]
dg.dataProvider = dp;
}
Copy link to clipboard
Copied
to search for a particular zip, call zipF:
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE,completeF);
urlLoader.load(new URLRequest("cust-list-delim.csv"));
var dg:DataGrid;
var dpA:Array = [];
function completeF(e:Event):void{
var dataS:String = e.target.data;
var dataA:Array = dataS.split("\n").join("").split("\r");
var itemA:Array;
for(var i:int=0;i<dataA.length;i++){
itemA = dataA.split(",");
dpA.push({"Business":itemA[1],"Name":itemA[2],"Address":itemA[3],"City":itemA[4],"State":itemA[5],"Zip":itemA[6]});
}
var dp:DataProvider = new DataProvider(dpA);
dg.columns = ["Business","Name","Address","City","State","Zip"]
dg.dataProvider = dp;
}
function zipF(zip:String):DataProvider{
var dp_zipA:Array=[];
for(var i:int=0;i<dpA.length;i++){
if(dpA.Zip==zip){
dp_zipA.push({"Business":dpA.Business],"Name":dpA.Name,"Address":dpA.Address,"City":dpA.City,"State":dpA.State});
}
}
return new DataProvider(dp_zipA);
}
Copy link to clipboard
Copied
Lets say I have a text box above the data grid, would I be able to call from that text box? Sorry if thats a stupid question.
Copy link to clipboard
Copied
yes, but you'll probably need to use a button to call zipF or make some assumptions about the zip code (eg, call zipF when the textfield has the 5th digit entered).
Copy link to clipboard
Copied
Thanks I will give this a shot.
Copy link to clipboard
Copied
you're welcome.
(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)
Copy link to clipboard
Copied
Ok, Im just now back on this project.
Should I add this function to the existing code to pull the zip codes?
function zipF(zip:String):DataProvider{
var dp_zipA:Array=[];
for(var i:int=0;i<dpA.length;i++){
if(dpA.Zip==zip){
dp_zipA.push({"Business":dpA.Business,"Name":dpA.Name,"Address":dpA.Address,"City":dpA.City,"State":dpA.State});
}
}
return new DataProvider(dp_zipA);
}
Copy link to clipboard
Copied
nothing i've suggested has been helpful?
Copy link to clipboard
Copied
Oh my goodness yes it has! I am sorry let me re phrase. I am such a novice I think it comes across as sounding unappreciative.
Copy link to clipboard
Copied
This has been a few months since I have started this journey.
I am pulling in the csv file correctly.
I have an input text field that I would like to use to search and list zip codes.
You had posted a search function
function zipF(zip:String):DataProvider{
var dp_zipA:Array=[];
for(var i:int=0;i<dpA.length;i++){
if(dpA.Zip==zip){
dp_zipA.push({"Business":dpA.Business,"Name":dpA.Name,"Address":dpA.Address,"City ":dpA.City,"State":dpA.State});
}
}
return new DataProvider(dp_zipA);
}
I am trying to understand it.
Do I give the input text field the property name zipF? Or create a sep button?
Again I am sorry for being such a noob. But this is very exciting!
Copy link to clipboard
Copied
you call the zipF and pass the zip code (as a string). zipF returns a dataprovider of matching zip codes. each object contains all the data you showed was in your csv file.
if your input textfield is input_tf, you could use:
somebtn.addEventListener(MouseEvent.CLICK,searchF);
function searchF(e:MouseEvent):void{
// i assume you want to display this in datagrid, eg dg
dg.dataProvider=zipF(input_tf.text);
}
Copy link to clipboard
Copied
Sir, you are a god among men. I owe you a coffee!
If you have a ko-fi.com account I will gladly get you a cup of brain juice!
Copy link to clipboard
Copied
you're welcome.
(and i'd never heard of ko-fi, but after checking i created an account - http://ko-fi.com/H2H6EXKQ)
Copy link to clipboard
Copied
I have added the button zipF and I am using the function you posted for zipF but I am getting an error.
Scene 1, Layer 'Layer_13', Frame 5, Line 31, Column 10 1023: Incompatible override.
Do I need to give the input text box a name? Or call that?