user4468525
user4468525

Reputation:

Filter datagrid based on arraycollection data in flex

I have

  1. One arraycollection called ordersAC which contains number of dynamic data like orderId.
  2. Another arraycollection is the dataprovider of the datagrid called ordersRecordAC, Contains (orderId, orderTitle, orderDescription, price).

DataGrid contains 4 columns:

No.   OrderTitle   OrderDescription   Price

Now, DataGrid has 100 record. And I want to filter DataGrid using first arraycollection(ordersAC) which is dynamically changed every time.

like: ordersAC has 5 orderId 1521, 2154, 2233, 5484, 2351

then in DataGrid display only 5 records depend on orderId.

I tried following ways but didn't work:

private function onSearchRecordClick(event:FlexEvent):void
{
    var orderAC:ArrayCollection = ordersGridId.orderAC;
    for(var i:int = 0; i<ordersRecordAC.length-1;i++)
    {
        orderAC.filterFunction = filterRows; 

        function filterRows(item1:Object):Boolean 
        {
            if(item1.orderId == ordersRecordAC[i])
                return true;
            else
                return false;
        }
    }
    orderAC.refresh();
}

<mx:DataGrid id="ordersGridId" lockedColumnCount="5" dataProvider="{orderAC}" sortableColumns="true">

Hope Understand my question.

Thanks.

Upvotes: 1

Views: 354

Answers (1)

seand
seand

Reputation: 71

I would do the following w/ your code.

private var orderAC:ArrayCollection; // assign this somewhere else

private function onSearchRecordClick(event:FlexEvent):void
{
  if(!orderAC.filterFunction)
    orderAC.filterFunction = filterRows; 
  orderAC.refresh();
}

private function filterRows(item1:Object):Boolean 
{
  for(var i:int = 0;i < ordersRecordAC.length;i++)
  {
    if(item1.orderId == ordersRecordAC[i])
      return true;
  }
  return false;
}

Upvotes: 1

Related Questions