I ahve an ADG table with icons in some Columns as data , I was tring to add
filtering for this columns , the text filtering works fine for columns which
has String as data. Iwould like to add multiple filtering for the column with
icons as the data, i can multiple filter these columns if i give the string
value of the icon as the checkbox seleced value, but I want to add the icon
itself to the checkbox filter insted of the String value of the icon and filter
it , is this possible? Any help is appreciated.
For Example I have
a checkbox with the image string value as "hicon1.png", "hicon2.png" etc and if
i check or uncheck these valuse it is filtering correctly the icon columns ,
but I want to add the icon to this checkbox control instead of the above
strings, how can i do that ? Also if I managed to add this do this filter the
valuse as i select or unselect the icons?
Ican not put the whole source since there are many files, but any idea on how
to do this is appraciated.
thanks in advance,
Ann.
Code Sample is below
<?xml version="1.0" encoding="utf-8"?>
<DropDownFilterEditorBase
xmlns="controls.advancedDataGridClasses.filterEditors.*"
xmlns:mx="http://www.adobe.com/2006/mxml" width="{column.width}">
<mx:Script>
<![CDATA[
import controls.advancedDataGridClasses.filters.MultipleChoiceFilter;
import mx.controls.Alert;
import mx.collections.ArrayCollection;
import mx.collections.Sort;
[Bindable]
public var filter:MultipleChoiceFilter;
[Bindable]
public var lbls:ArrayCollection;
[Bindable]
var iconidx:int=-1;
[Bindable]
var lbl:String = "";
override protected function columnChanged():void
{
if (!column.filter || !column.filter is MultipleChoiceFilter)
{
column.filter = new MultipleChoiceFilter(column);
}
filter = column.filter as MultipleChoiceFilter;
}
]]>
</mx:Script>
<mx:CheckBox id="allCheckbox" label="All" selected="true"
change="{allCheckbox.selected ? filter.selectAll() : filter.deselectAll();
labelList.executeBindings(true)}"
creationComplete="{allCheckbox.setFocus()}"/>
<mx:List id="labelList" dataProvider="{filter.labels}" width="100%">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox label="{data}"
selected="{parentDocument.filter.selectedLabels.contains(data)}"
change="{selected ?
parentDocument.filter.selectLabel(data):parentDocument.filter.deselectLabel(data)}">
</mx:CheckBox>
</mx:Component>
</mx:itemRenderer>
</mx:List>
</DropDownFilterEditorBase>
file 2
package com.ca.controls.advancedDataGridClasses.filters
{
import controls.advancedDataGridClasses.MAdvancedDataGridColumn;
import controls.advancedDataGridClasses.MAdvancedDataGridEvent;
import flash.events.Event;
import mx.collections.ArrayCollection;
import mx.collections.Sort;
import mx.controls.Image;
import mx.controls.Alert;
/**
* The MultipleChoiceFilter class defines MAdvancedDataGrid column filter
* exposing the list of different values appearing in MAdvancedDataGrid
* column and allowing user to select which values should be displayed.
*
* This filter should be applied to columns containing repeating values.
*/
public class MultipleChoiceFilter extends ColumnFilterBase
{
/**
* Constructor.
*/
public function MultipleChoiceFilter(column:MAdvancedDataGridColumn)
{
super(column);
advancedDataGrid.addEventListener(MAdvancedDataGridEvent.ORIGINAL_COLLECTION_CHANGE,
originalCollectionChandeHandler);
updateLabels();
}
/**
* List of all different labels appearing in column related to this filter.
*/
[Bindable]
public var labels:ArrayCollection;
[Bindable]
public var lbls:ArrayCollection;
[Bindable]
var lbl:String = "";
/**
* List of selected labels.
* Only items with labels from this list will be included in MAdvancedDataGrid
data provider.
*/
[Bindable]
public var selectedLabels:ArrayCollection = new ArrayCollection();
/**
* Select given label by adding it to <code>selectedLabels</code> list.
*/
public function selectLabel(label:String):void
{
if (!selectedLabels.contains(label))
{
selectedLabels.addItem(label);
}
commitFilterChange();
}
/**
* Deselect given label by adding it to <code>selectedLabels</code> list.
*/
public function deselectLabel(label:String):void
{
if (selectedLabels.contains(label))
{
selectedLabels.removeItemAt(selectedLabels.getItemIndex(label));
}
commitFilterChange();
}
/**
* Select all labels.
*/
public function selectAll():void
{
for each (var label:String in labels)
{
if (!selectedLabels.contains(label))
{
selectedLabels.addItem(label);
}
}
commitFilterChange();
}
/**
* Deselect all labels.
*/
public function deselectAll():void
{
selectedLabels.removeAll();
commitFilterChange();
}
/**
* Update <code>isActive</code> and then inform MAdvancedDataGrid about the
change to this filter.
*/
override protected function commitFilterChange():void
{
var active:Boolean = false;
for each (var label:String in labels)
{
if (!selectedLabels.contains(label))
{
active = true;
break;
}
}
_isActive = active;
super.commitFilterChange();
}
/**
* Update labels list by iterating through MAdvancedDataGrid original collection.
*/
protected function updateLabels():void
{
//TODO: save filter selection when data are updated
var nl:ArrayCollection = new ArrayCollection();
var labelArray:ArrayCollection = new ArrayCollection();
for each (var item:Object in advancedDataGrid.originalCollection)
{
var label:String = column.itemToLabel(item);
if (label && !nl.contains(label))
{
nl.addItem(label);
}
}
nl.sort = new Sort();
nl.refresh();
labels = nl;
deselectAll();
selectAll();
}
/**
* MAdvancedDataGrid original collection change event handler.
*/
protected function originalCollectionChandeHandler(event:Event):void
{
updateLabels();
}
/**
* Flag indicating wether this filter is active
* i.e may eliminate some items from MAdvancedDataGrid data provider.
*/
[Bindable("filterChanged")]
override public function get isActive():Boolean
{
return _isActive;
}
/**
* @private
* Storage variable for <code>isActive</code> flag.
*/
protected var _isActive:Boolean = false;
/**
* Test if given MAdvancedDataGrid item should remain in MAdvancedDataGrid data
provider.
*/
override public function filterFunction(obj:Object):Boolean
{
return selectedLabels.contains(column.itemToLabel(obj));
}
}
}