“Filter results in DataGrid” Flex Tutorial
April 29th, 2008 at 10:21pm Administrator
If you're new here, you may want to subscribe to my RSS feed. If you like my site, consider linking back. I prefer text "Free Flash Tutorials" to http://blog.franto.com
Thanks for visiting my site! If you need anything just contacting through Contact page or Gtalk widget
Table of contents for DataGrid
- Custom header in DataGrid
- Custom header in DataGrid - part 2
- “Filter results in DataGrid” Flex Tutorial
This is new post in my DataGrid Series Flex Tutorials. This tutorial shows you how to filter rows for searched keyword. It's quite easy, since dataProvider for DataGrid is ArrayCollection, and ArrayCollection has variable filterFunction. It simple expect function which will filter correct rows for you. So basically, you have Datagrid and dataProvider is defined like this
-
[Bindable] public var dpRows:ArrayCollection;
then you can create filter function in this simple way:
-
public function filterResults():void
-
{
-
dpRows.filterFunction = _sortRows;
-
dpRows.refresh();
-
}
and finally function, which filters results. It returns true for row, which will be visible, and false for row which will be hiden.
-
private function _sortRows(item:Object):Boolean
-
{
-
var col:String = cmbCol.selectedItem.data as String;
-
var key:String = keyword.text;
-
-
key = key.toLowerCase();
-
-
if (key != "")
-
{
-
if (col != "any")
-
{
-
var value:String = item[col];
-
value = value.toLowerCase();
-
-
if (value.indexOf(key)>= 0)
-
{
-
return true;
-
}
-
} else {
-
for (var o:String in item)
-
{
-
value = item[o];
-
value = value.toLowerCase();
-
if (value.indexOf(key)>= 0)
-
{
-
return true;
-
}
-
}
-
}
-
} else {
-
return true;
-
}
-
-
return false;
-
}
It's quite simple tutorial. Here you can see source code for example which follows.
In next tutorial for DataGrid I will show you how you can add Button into cell. We will use custom itemRenderer for DataGridColumn.
If you have any questions, or suggestions for tutorial, please let me know...
Enjoy.
AIR, AirTips, Flash, Flex, FlexTips, Macromedia Tips, Tutorial, tutorialsEntry Filed under: Tutorial, tutorials, Macromedia Tips, AirTips, FlexTips, Flex, AIR, Flash
»Related posts:
- Custom header in DataGrid - part 2
- Flex or AIR tutorials
- Custom header in DataGrid
- Share Knowledge
- How to Skin a Flex Video Player Tutorial from Dolores Joya
- Embedding fonts in Flex: just some glyphs
- FlexAir top on Google
- CellRenderer rowHeight
- Tutorial on Delegate class by Patrick Mineault
- FlexTips
- Flex 3 beta 2 Autocompletation time
- Flash Maps Collection
- The Flare Visualization Toolkit
- Adobe Image Foundation Toolkit Technology Preview
- Collections of AIR applications
- AS3: Pathfinder in big mazes
- Sandy tutorial: .ASE file export
- Videobomb.com - best web videos
- Torino 2006: Slovakia on Olympic Games - part I
- FlexAir is growing






April 30th, 2008 at 3:17 pm
Hi,
I’m interested in buying links from your blog
Please contact me by email
Thanks
May 2nd, 2008 at 5:19 pm
You might find the following useful too
http://www.tink.ws/blog/filtereddatagrid/
I implemented it this way as I was using the same ArrayCollection in more than one place, and I needed each to be filtered in a different way, without affecting the other (i.e. not affecting the original data).