ArrayCollection DataGrid filter Example update

Jul
28

**UPDATE**

Thanks to the help of Nolan I was able to get it to:

  1. works with case-sensitivity
  2. and resets data as you type.

————————————-
I redid the ArrayCollection example so take a look at this example:

[as]
< ?xml version="1.0" encoding="utf-8"?>

< ![CDATA[
import mx.collections.*;

private var collectionArray:Array;
[Bindable]
private var collectionData:ArrayCollection;

private function init():void
{
collectionArray = [{first: 'Dave', last: 'Matthews'},
{first: 'Dave', last: 'Chappelle'},
{first: 'Amy', last: 'Grant'},
{first: 'Bilbo', last: 'Baggins'},
{first: 'Jessica', last: 'Tandy'},
{first: 'Jessica', last: 'Simpson'},
{first: 'Paris', last: 'Hilton'}];
collectionData = new ArrayCollection(collectionArray);
}

public function filter():void {

collectionData.filterFunction = filterFirst;
collectionData.refresh();

}

public function filterReset():void {

collectionData.filterFunction = null;
collectionData.refresh();

}

private function filterFirst(item:Object):Boolean
{

return item.first.match(new RegExp(searchField.text, 'i'))

//return( item['first'].indexOf( searchField.text ) > -1 );
//return item['first'].match(new RegExp(string, “i�))

}

private function search():void
{
if(searchField.text !=”)
{
filter()
}
else
{
filterReset()
}
}
]]>

[/as]

 

One Response to “ArrayCollection DataGrid filter Example update”

  1. Kenneth says:

    How would I implement this with XML instead of ArrayCollection?

    Thanks!

Leave a Reply