Er, I don't think you're actually instantiating the event:
public function processFilterChangedEvent(pEvent:Object) {
//[MATT] added = new Object()
var eventObject : Object = mew Object();
eventObject.type = "modelChanged";
eventObject.eventName = "updateAll";
dispatchEvent(eventObject);
}
-----Original Message-----
From: Ashley Streb
To: [email protected]
Sent: 3/31/2005 7:44 AM
Subject: [flexcoders] Filtering Results from a DataProvider
I wrote a custom data provider that will filter results from a wrapped
DataProvider. The idea was that you could plug in different filters;
filter on partially typed words, location etc.
This custom data provider (FilterDataProvider) extends the
mx.control.listclasses.DataProvider class.
I'm running into two problems and the solutions to those problems allude
me.
The first is that my DataGrid is not receiving modelChanged events that
my FilterDataProvider fires.
The second is that my DataGrid is not setting the selectedItem property
when I click on a row. It also does not highlight the row that I
clicked.
Here is the code from my FilterDataProvider (I've removed some of the
extraneous function calls for brevity/readability). The important thing
to note is that the FilterDataProvider receives events from its
configured filters indicating that something about them has changed and
they need to refilter the data. These events are received by the
filterDataProvider, which in turn fires off a modelChanged event. I've
confirmed that the FilterDataProvider is indeed receiving events from
its configured filters (alerting out messages), and I've also confirmed
that the DataGrid that this filterDataProvider is configured on never
receives the modelChanged event. (I extended the DataGrid class and
overrode the modelChanged method, alerted out a message before calling
super.modelChanged)
Any help is appreciated. Thanks!
class FilterDataProvider
extends DataProvider
{
public var source : DataProvider;
public var filters : Array;
public function get length():Number {
var sourceLength:Number = mSource.length;
var filteredLength : Number = 0;
for (var i:Number = 0; i < sourceLength; i++) {
var item = mSource.getItemAt(i);
if (accept(item)) {
filteredLength++;
}
}
return filteredLength;
}
public function getItemAt(pIndex:Number) {
var sourceLength:Number = mSource.length;
for (var i:Number = pIndex + mOffset; i < sourceLength; i++)
{
var item = mSource.getItemAt(i);
if (accept(item)) {
return item;
}
}
return null;
}
private function accept(pItem) : Boolean
{
var filterLength:Number = mFilters.length;
for (var i:Number = 0; i < filterLength; i++) {
var filter:Filter = mFilters[i];
if (!filter.accept(pItem)) {
return false;
}
}
return true;
}
public function processFilterChangedEvent(pEvent:Object) {
var eventObject : Object;
eventObject.type = "modelChanged";
eventObject.eventName = "updateAll";
dispatchEvent(eventObject);
}
}
mxml registration...
<components:FilterDataProvider source="{remoteObject.result}"
id="filterProvider"/>
<components:FancyDataGrid id="videoGrid"
width="100%" height="100%" dataProvider="filterProvider">
-ashley
Yahoo! Groups Sponsor
ADVERTISEMENT
<http://us.ard.yahoo.com/SIG=129lfm2ti/M=298184.6018725.7038619.3001176/
D=groups/S=1705007207:HM/EXP=1112370417/A=2593423/R=0/SIG=11el9gslf/*htt
p://www.netflix.com/Default?mqso=60190075> click here
<http://us.adserver.yahoo.com/l?M=298184.6018725.7038619.3001176/D=group
s/S=:HM/A=2593423/rand=912110107>
_____
Yahoo! Groups Links
* To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<http://groups.yahoo.com/group/flexcoders/>
* To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> .
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/