1 Reply Latest reply on Jan 6, 2009 7:26 AM by rtalton

    filtering dataprovider of datagrid

    mtgna
      Hi

      Does anyone have an example or sample code for filtering results shown in a datagrid where the dataprovider is an
      arraycollection of a VO?

      For example,

      accountingdata:ArrayCollection = new ArrayCollection(ArrayUtil.toArray(event.result));
      //where event.result is VO retrieved from a remotecall.

      <mx:DataGrid id="mainList" dataProvider="{ accountingdata }" itemClick="itemClicked(event)">

      <mx:columns>
      <mx:DataGridColumn dataField="date" width="80"
      headerText="Date"/>
      <mx:DataGridColumn dataField="accountno" width="60"
      headerText="Account Number"/>
      <mx:DataGridColumn id ="debit" dataField="debit" headerText = "Debit" width="80" labelFunction="format" />
      <mx:DataGridColumn dataField="credit" headerText = "Credit" width="80" />

      </mx:columns>

      I have seen many examples online which use XML or hard code the arraycollection items but would appreciate examples that uses VO.

      Thanks.
        • 1. Re: filtering dataprovider of datagrid
          rtalton Level 4
          Use the filterFunction property of the ArrayCollection. It simply returns a true or false result.
          example:

          private function filterOnCredit(item:Object):Boolean{
          return (item.credit > 1200);
          }

          private function executeCreditFilter():void{
          accountingdata.filterFunction = filterOnCredit;
          accountingdata .refresh;
          }