How to filter flex datagrid with three check boxes.?
I am new to flex.
I need your help. Can anyone help me please.
My Requirement: Flex Datagrid should be filter based on 3 checkboxes.(Checkboxes can be checked with several combinations).
My Code:
Checkboxes:
Data Provider:
MXML code:
Here i have to filter the datagrid when i check the different combinations of 3 checkboxes. The checkbox values are from Staus column of arraycollection. When i select 'completed' checkbox and 'onhold' check box, datagrid should display only those records which have Status as "Completed" & "On Hold". Similarly for all combinations of c
Can anyone give simple solution please ?
Thanks, Anand.k
Use an ArrayCollection as your dataProvider and assign a filtering function to its filterFunction property :
var provider:ArrayCollection;
At the part where you instantiate your array, give it a filterFunction :
provider.filterFunction = myFilteringFunction;
With the code of the filterFunction like this :
private function myFilteringFunction(item:ObjectTypeInYourArray) : Boolean {
var show:Boolean;
if(item.completed == checkBox1.checked &&
item.onHold == checkBox2.checked){
show = true;
}
return show;
}
It's an example with two checkboxes. The type of value assigned to the completed and onHold attributes of your object may not be boolean so you'll have to convert them somehow before comparing them to the state of the checkboxes but I think you get the idea.
Basically the filterFunction that you pass to your arraycollection is applied to each of the items inside and return true or false depending on you code inside (e.g check if the object has the right values for its properties). When true
the values are showed
At the change events of your checkboxes, you refresh the dataProvider :
provider.refresh();
Hope that helps
精彩评论