2012-03-23 6 views
1

今日私はこれをどのように行うか検索しようとしていますが、これはよくわかりません。私が達成したいのは、データグリッド内のメッセージのリストが、別のクラスのデータプロバイダから来ていて、それがOracle DBから取得されるということです。私はすべてのユーザーにメッセージの可視状態を設定し、ボタンをクリックするだけでそのデータグリッドからフィルタリングする必要があります。非表示のチェックボックスがあり、その値がデータベースに設定されます。フィルタパラメータが行データ内にある場合、配列コレクションで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/でこれを行うのチュートリアルを見つけましたが、上記の問題点を把握することはできません、これは本当に、その難しいことはできませんそれをできる?

おかげで、

イアン

+0

フィルタ機能は、項目のプロパティに基づいてtrueまたはfalseを返しません。 messageVisibleがtrueに設定されているdataProviderのデータをフィルタリングする必要がありますか? – Francisc

+0

このリンクをチェックしてください:http://www.iwobanas.com/2009/06/datagrid-with-client-side-filtering-and-searching/私はそれが学習の観点からもコンポーネントとしても非常に素晴らしいと感じています:) – Sebastian

答えて

1

アイテムは長さと反復に含めるためのdataProviderの要素方法はdataProviderの各要素のために呼び出され、フラグ項目です。

 public function filterResults():void { 

      modelLocator.notification.messageList.filterFunction = filterRows; 

      modelLocator.notification.messageList.refresh(); 


     } 

     public function filterRows(item:Object):Boolean { 
      if(showAll) 
       return true; 
      if(item.messageVisible=="true") 
       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()" /> 
+0

それはそれを行いました。それを見て、それは簡単だとは信じられません。ありがとう@shaunhusain – idonaldson

関連する問題