我今天搜索了所有试图找到如何做到这一点,而不熟悉actionscript开始赶上我。我想完成的是:我有一个Datagrid中的消息列表来自另一个类中的数据提供者,而这个消息从Oracle数据库中获取它们。我需要所有用户在消息上设置可见状态,然后通过单击按钮将其过滤出数据网格。我有隐藏的复选框,并将该值设置到数据库中。当filter参数在行数据中时,我无法弄清楚如何让filterFunction与数组集合一起工作。基于行中的数据过滤数据网格,Flex
下面是代码
public function filterResults():void {
modelLocator.notification.messageList.filterFunction = filterRows;
modelLocator.notification.messageList.refresh();
}
public function filterRows(item:Object):Boolean {
//return true if row should stay visible
//return false if it should go away
var i:int;
if(showAll == false) {//checks whether this is coming from the hide or show all button
//Somehow need to interrogate the row data to check if messageVisible is set to true or false
/* if (showAll == false) {
return false;
}else {
return true;
}
return false; */
}
public var showAll:Boolean;
public function showAllMessages():void{
showAll = true;
filterResults();
}
public function hideMessages():void{
showAll = false;
filterResults();
}
]]>
</mx:Script>
<mx:VBox>
<component:EditMessage id="editMessage" width="930" height="445"/>
<mx:Panel id="messageListPanel" title="Message History" layout="vertical" width="930" height="196" horizontalAlign="left">
<mx:DataGrid id="messageDataGrid" dataProvider="{modelLocator.notification.messageList}"
width="910" height="139" enabled="true" mouseEnabled="true" editable="false"
rowCount="5" itemClick="{selectMessage()}">
<mx:columns>
<mx:DataGridColumn headerText="Date Created" labelFunction="formatCreateDate" width="60"/>
<mx:DataGridColumn headerText="From" dataField="senderEmail" width="100"/>
<mx:DataGridColumn headerText="Subject" dataField="subject" width="100"/>
<mx:DataGridColumn headerText="Start Date" labelFunction="formatStartDate" width="60"/>
<mx:DataGridColumn headerText="End Date" labelFunction="formatEndDate" width="60" />
<mx:DataGridColumn headerText="Date Sent" labelFunction="formatSendDate" width="60" />
<mx:DataGridColumn headerText="Sender Netid" dataField="senderNetId" width="50" />
<mx:DataGridColumn headerText="Sender Name" dataField="senderName" width="80" />
<mx:DataGridColumn headerText="Message" dataField="message" width="100" />
<mx:DataGridColumn headerText="Message Id" dataField="id" width="10" />
</mx:columns>
</mx:DataGrid>
</mx:Panel>
</mx:VBox>
<mx:Button id="showMessagesBtn" x="786" y="452" label="Show All Messages" click="showAllMessages()"/>
<mx:Button id="hideMessagesBtn" x="665" y="452" label="Hide Messages" click="hideMessages()" />
我发现了一个教程在这里http://franto.com/filter-results-in-datagrid-flex-tutorial/传入的文本这样做,但无法弄清楚上述问题,这真的不能那么难,它可以?
谢谢,
伊恩
您的过滤器函数根据item属性不返回true或false。你想过滤messageVisible设置为true的dataProvider中的数据吗? – Francisc 2012-03-23 23:11:03
看看这个链接:http://www.iwobanas.com/2009/06/datagrid-with-client-side-filtering-and-searching/。从学习的角度和作为一个组件,我发现它非常棒!:) – Sebastian 2012-03-24 09:47:57