Rinaldi
June 24th, 2007, 09:45 AM
Hello, I'm trying to use filterFunction to filter part of the data that is an ArrayCollection and it's showed in a datagrid. Well, I don't know if this class can only be applied using coldfusion, because I think that the only thing which cold fusion does is get the data from the database. So I’m getting the data from a database that is available in ArrayCollection of objects which is called myServiceData. In my application I want to choose in a combo determined period that my data in the database was modified and display it in the datagrid. There is the date field already to be consulted. There is also a class called DateMath that return date wished.
Here is the code:
<mx:Script>
<![CDATA[
private var periodArray:Array = ["Today", "This Week", "This Month", "Last 3 Months"];
[Bindable]
public var periodCollection:ArrayCollection = new ArrayCollection(periodArray);
public function periodFilter():void
{
if (comboPeriod.selectedIndex == 3)
{
myServiceData.filterFunction = null;
}
else
{
myServiceData.filterFunction = periodFilterFunction;
}
myServiceData.refresh();
}
public function periodFilterFunction(data):Boolean
{
var now:Date = new Date();
var dateMath:DateMath = new DateMath();
var dateToFilter:Date = new Date();
switch (comboPeriod.selectedIndex)
{
case 0:
dateToFilter = dateMath.addDays(now, -1);
break;
case 1:
dateToFilter = dateMath.addWeeks(now, -1);
break;
case 2:
dateToFilter = dateMath.addWeeks(now, -4);
break;
}
//return (dateToFilter < data.creation);
return true;
}
]]>
</mx:Script>
<mx:ComboBox id="comboPeriod" selectedIndex="3" dataProvider="{periodCollection}"
change="periodFilter()"></mx:ComboBox>
Just wondering how do I use filterfunction to filter the date that I got.
Thank you very much.
Here is the code:
<mx:Script>
<![CDATA[
private var periodArray:Array = ["Today", "This Week", "This Month", "Last 3 Months"];
[Bindable]
public var periodCollection:ArrayCollection = new ArrayCollection(periodArray);
public function periodFilter():void
{
if (comboPeriod.selectedIndex == 3)
{
myServiceData.filterFunction = null;
}
else
{
myServiceData.filterFunction = periodFilterFunction;
}
myServiceData.refresh();
}
public function periodFilterFunction(data):Boolean
{
var now:Date = new Date();
var dateMath:DateMath = new DateMath();
var dateToFilter:Date = new Date();
switch (comboPeriod.selectedIndex)
{
case 0:
dateToFilter = dateMath.addDays(now, -1);
break;
case 1:
dateToFilter = dateMath.addWeeks(now, -1);
break;
case 2:
dateToFilter = dateMath.addWeeks(now, -4);
break;
}
//return (dateToFilter < data.creation);
return true;
}
]]>
</mx:Script>
<mx:ComboBox id="comboPeriod" selectedIndex="3" dataProvider="{periodCollection}"
change="periodFilter()"></mx:ComboBox>
Just wondering how do I use filterfunction to filter the date that I got.
Thank you very much.