PDA

View Full Version : filterFunction



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.

Rinaldi
June 25th, 2007, 06:03 AM
Hi I'm getting the error "1063: Argument count mismatch" in the line which periodFilterFunction is called and I checked if there was any problem which it doesn't, because the arguments mach with those required. In the code that I had left don't show, but the data is type required is "TopicosDetails" and it is the same type of the item through to the function, so what else could be? For further speculation these are the links to the complete project.

testWebService.mxml (http://www.camarismo.com/flex/testWebService.mxml)
TopicoDetails.as (http://www.camarismo.com/flex/dto/TopicoDetails.as)
DateMath.as (http://www.camarismo.com/flex/Classes/DateMath.as)
link to the path: http://www.camarismo.com/flex/Classes/
Thank you very much for your help.