Skip to main content
Known Participant
April 9, 2018
Answered

How to search a data grid that is loading a csv file?

  • April 9, 2018
  • 1 reply
  • 1348 views

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.

This topic has been closed for replies.
Correct answer kglad

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!


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);

}

1 reply

kglad
Community Expert
Community Expert
April 10, 2018

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.

dubsdubsAuthor
Known Participant
April 10, 2018

Would it help to show you how Im pulling in the csv file?

kglad
Community Expert
Community Expert
April 10, 2018

i assume you're using a urlloader and the more relevant issue is the structure of the csv file