Hi,

I have started this functionality and even I got success but upto an 
extent and now I am stucked.

I have rendered the header and placed a comboBox using 
testCombo.mxml. Here I have a few queries like:

1. How can I get rendered header's column Index so that I can the 
unique value of that purticular column n populate that combo box?

2. Currently, when I change the combo item, it filters my 
arrayCollection and show the data accordingly but it doesnt keep 
selected the selected Item. Suggest something to rectify.

3. How Can I Hide/Show a Column of a dataGrid? or How Can I 
Add/Delete a Column of a DataGrid?

4. How Can I get/set the column Index or Label on which Sorting is 
implemented?

5. How can I get/set width of each column of a dataGrid?

I have some questions also in my mind... but that'll for next 
time .................. ;)

I have also pasted the code below.

Please help me to resolve these issues..

Thanks in advance...
Sanjay Sharma

Code:::::: MainGrid.mxml :::::::::::::::

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; 
layout="absolute" initialize="doInit()"   >
<mx:Script>
        <![CDATA[
                import mx.controls.Alert;
                import mx.collections.*;
                
                [Bindable]
       public var authorsDataProvider : ArrayCollection = new 
ArrayCollection( [
            { Selection: "", Country: "USA", Gold: 35, 
Status:"Active", URL:"http://www.google.com"; },
            { Selection: "", Country: "China", Gold: 32, 
Status:"Deactive",URL:"http://www.yahoo.com"},
            { Selection: "", Country: "Russia", Gold: 
27,Status:"Deactive", URL:"http://www.hotmail.com"; },
            { Selection: "", Country: "India", Gold: 12, 
Status:"Active",URL:"http://www.gmail.com"},
            {Selection: "", Country: "Russia", Gold: 27, 
Status:"Deleted",URL:"http://www.hotmail.com"; },
            {Selection: "", Country: "Russia", Gold: 27, 
Status:"Deleted",URL:"http://www.hotmail.com"; },
            { Selection: "", Country: "China", Gold: 32, 
Status:"Deactive",URL:"http://www.yahoo.com"},
            { Selection: "", Country: "Russia", Gold: 
27,Status:"Deactive", URL:"http://www.hotmail.com"; },
            { Selection: "", Country: "India", Gold: 12, 
Status:"Active",URL:"http://www.gmail.com"},
            {Selection: "", Country: "Russia", Gold: 27, 
Status:"Deleted",URL:"http://www.hotmail.com"; },
            {Selection: "", Country: "Russia", Gold: 27, 
Status:"Deleted",URL:"http://www.hotmail.com"; },
            { Selection: "", Country: "China", Gold: 32, 
Status:"Deactive",URL:"http://www.yahoo.com"},
            { Selection: "", Country: "Russia", Gold: 
27,Status:"Deactive", URL:"http://www.hotmail.com"; },
            { Selection: "", Country: "India", Gold: 12, 
Status:"Active",URL:"http://www.gmail.com"},
            {Selection: "", Country: "Russia", Gold: 27, 
Status:"Deleted",URL:"http://www.hotmail.com"; },
            {Selection: "", Country: "Russia", Gold: 27, 
Status:"Deleted",URL:"http://www.hotmail.com"; } ]);
                
                public function doInit():void{
                }
                public function filterFnc(item:Object):Boolean {
                return item.Gold == 27 ;
          }
                public function filterFnc1(item:Object):Boolean {
                                //Alert.show("item: "+item.toString
());
                                //Alert.show("item.Gold.toString()")
                return item.Status == "Deactive" ;
          }

        ]]>
</mx:Script>
<mx:Panel title="Header Filter" width="100%" height="100%">
      <mx:DataGrid  allowMultipleSelection="true"  id="grid" 
dataProvider="{authorsDataProvider}" width="100%" height="100%" 
sortableColumns="false"   >
        <mx:columns>
          <mx:Array>
            <mx:DataGridColumn itemRenderer="MyContactEditable" 
resizable="false"  dataField="Selection" width="80" />
            <mx:DataGridColumn width="300" headerText="Country" 
dataField="Country"   />
            <mx:DataGridColumn width="300" headerText="Status" 
dataField="Status" headerRenderer="testCombo"/>
            <mx:DataGridColumn width="300" headerText="Gold" 
dataField="Gold" />
         </mx:Array>
        </mx:columns>
      </mx:DataGrid>
    </mx:Panel>
</mx:Application>


:::::::::::::::::::::::::: testCombo.mxml ::::::::::::::::::

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"; 
preinitialize="init()">  
<mx:Script>
                <![CDATA[
                        import mx.controls.listClasses.ListData;
                        import mx.controls.Alert;
                        import 
mx.controls.dataGridClasses.DataGridListData;
            import flash.events.Event;
                import mx.events.DataGridEvent;

                        
                        public var Listener:Object = new Object();
                        public  var myListData:DataGridListData = 
DataGridListData(myListData);
                                
                        [Bindable]  
                        public var statusArray:Array = ["All",
                        "Active",
                        "Deactive",
                        "Deleted"];
                        
                        public function init():void{
                                addEventListener("initialize", 
handleDataChanged);
                        }
                        public function handleDataChanged
(event:Event):void { 
                                
                                
                                //var ttext:String ="row index: " + 
String(myListData.rowIndex) +                     " column index: " 
+ String(myListData.columnIndex);
                                //Alert.show("ttext:: "+myListData);
                        
                } 
            public function changeCombo():void{
                //Alert.show("changeCombo:: ");
                parentDocument.authorsDataProvider.filterFunction = 
filterFnc;
                parentDocument.authorsDataProvider.refresh();
                //var testData:ListData = ListData
(parentDocument.listData);
                                
            }
            public function filterFnc(item:Object):Boolean {
                                //Alert.show("item: "+item.toString
());
                                //Alert.show("item.Gold.toString()")
                return item.Status == 
cboAuthorsStatusFilter.selectedItem ;
                 }
                    ]]>
        </mx:Script>  
    <mx:ComboBox width="100%" id="cboAuthorsStatusFilter"
    dataProvider="{statusArray}"   change="changeCombo()" /> 
        <mx:Label id="headLabel" 
text="{cboAuthorsStatusFilter.selectedItem}" />     
        
</mx:HBox>


--- In flexcoders@yahoogroups.com, "sanjaypmg" <[EMAIL PROTECTED]> wrote:
>
> Hi,
> 
> I have tried to get column index in my testCombo.mxml by 
importing " 
> mx.controls.dataGridClasses.DataGridListData" But I am not able to 
> get column index or column name.
> 
> Could anyone please help me? so that i can complete the task and 
> populate code for all.
> 
> Thanks,
> Sanjay sharma
> 
> --- In flexcoders@yahoogroups.com, "phipzkillah" <pkrasko@> wrote:
> >
> > Sanjay,
> > 
> > Did you have any luck converting the DG Header Filter cell 
> renderer to
> > Flex 2.0?  These are the cons that were posted with the code 
> snippet:
> > 
> > CONS
> > 1) you must maintain the same dataProvider.
> > 2) sorting is no good. you might want to re-sort after a filter 
is
> > done (but providing events and what not are still something I 
need 
> to
> > provide, probable a modelChanged event utilizing the 
> eventName 'filter'
> > 
> > There is still a lot to do for this renderer to make it more 
> usable,
> > but I figure I've gotten everyone to a dropping off point it 
> shouldn't
> > be too hard. As I progress with this I'll post more to this 
thread
> > 
> > #########
> > 
> > I'm not sure exactly what you are trying to do.  Do you just 
simply
> > want a combo-box that you select a field in the list and have it 
> sort
> > the datagrid?  If so I believe you need to use an ArrayList 
> collection
> > for your dataprovider.  
> > 
> > The link that I gave you earlier seems like it would be the best 
> for
> > filtering a datagrid as you would be able to filter on each
> > field/column by clicking on the header and selecting an item - 
> which
> > is exactly what Excel does.
> > 
> > If you were able to convert that datagrid header filter cell 
> renderer
> > to Flex 2.0 can you please post the source up here?
> > 
> > -Phil
> > 
> > --- In flexcoders@yahoogroups.com, "sanjaypmg" <sanjaypmg@> 
wrote:
> > >
> > > Hi,
> > > 
> > > I have tried it but facing a problem when I try to access 
> > > DataCollection from another MXML testCombo.mxml. 
> > > 
> > > Please Suggest:::
> > > 
> > > See the following Code:
> > > 
> > > filterTest.mxml::::
> > > 
> > > <?xml version="1.0" ?>
> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";  
> > > xmlns="../*"  >
> > > 
> > > <mx:Script>
> > > <![CDATA[
> > >           import mx.collections.ArrayCollection;
> > >           import mx.core.ClassFactory;
> > > 
> > > public var object2:Object = new Object();
> > > public var object:Object = new Object();
> > > [Bindable]
> > >   
> > >    
> > >    [Bindable]
> > >        public var authorsDataProvider : ArrayCollection = new 
> > > ArrayCollection( [
> > >             { Country: "USA", Gold: 35, Status:"Active", 
> > > URL:"http://www.google.com"; },
> > >             { Country: "China", Gold: 32, 
> > > Status:"Deactive",URL:"http://www.yahoo.com"},
> > >             { Country: "Russia", Gold: 27,Status:"Deactive", 
> > > URL:"http://www.hotmail.com"; },
> > >             { Country: "India", Gold: 12, 
> > > Status:"Active",URL:"http://www.gmail.com"},
> > >             {Country: "Russia", Gold: 27, 
> > > Status:"Deleted",URL:"http://www.hotmail.com"; },
> > >             {Country: "Russia", Gold: 27, 
> > > Status:"Deleted",URL:"http://www.hotmail.com"; } ]);
> > > 
> > > ]]>
> > > </mx:Script>
> > > <mx:Panel title="Header Filter" width="100%" height="100%">
> > >       <mx:DataGrid id="grid" 
> dataProvider="{authorsDataProvider}" 
> > > width="100%" height="100%" sortableColumns="false"   >
> > >         <mx:columns>
> > >           <mx:Array>
> > >             <mx:DataGridColumn width="300" 
headerText="Country" 
> > > dataField="Country" />
> > >             <mx:DataGridColumn width="300" headerText="Value" 
> > > dataField="Gold"/>
> > >             <mx:DataGridColumn width="300" headerText="Status" 
> > > dataField="Status" headerRenderer="testCombo"/>
> > >             <mx:DataGridColumn width="300" headerText="URL" 
> > > dataField="URL"/>
> > >           </mx:Array>
> > >         </mx:columns>
> > >       </mx:DataGrid>
> > >     </mx:Panel>
> > > </mx:Application>
> > > 
> > > 
> > > 
> > > testCombo.mxml:::::
> > > 
> > > 
> > > <?xml version="1.0" encoding="utf-8"?>
> > > 
> > > <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml";>
> > >     <mx:Label text="Sale Price!"/>
> > >     <mx:ComboBox id="cboAuthorsStatusFilter"
> > >     dataProvider="{authorsStatusArray}" 
> > >     change="filterAuthorsGrid();"
> > >     >
> > >     
> > >     
> > >     <!-- dataProvider="{_parent._parent.gridData}">-->
> > >   <mx:Script>
> > >           <![CDATA[
> > >                   import mx.controls.Alert;
> > >                   import mx.collections.*;
> > >                   [Bindable]  
> > >                   public var authorsArray:Array = ["All",
> > >                   "Active",
> > >                   "Deactive",
> > >                   "Deleted"];
> > >                   
> > >                    [Bindable] 
> > >                   public var authorsStatusArray : Array = 
> > > populateAuthorsStatusArray(authorsArray);
> > > 
> > >                   public function populateAuthorsStatusArray
> > > (authorsArray:Array):Array
> > >                   {
> > >                           //Alert.show
> > > ("authorsArray: "+authorsArray.toString())
> > >                           var statusArrayHashMap : Object = 
> > > new Object();   
> > >                           var statusArray : Array = new Array; 
> > >                           var n:int = authorsArray.length; 
> > >                           for (var i:int = 0; i < n; 
> > > i++)             
> > >                           {                    
> > >                                   if (statusArrayHashMap
> > > [authorsArray] == undefined)                    
> > >                           
> > >   {                               
> > >                                           statusArrayHashMap
> > > [authorsArray] = new Object();                               
> > >                                           statusArray.push
> > > (authorsArray[i]);                    
> > >                                   } else
> > >                                   {
> > >                                           statusArray.push
> > > (authorsArray [i]);  
> > >                                   }
> > >                                              
> > >                           }             
> > >                           return statusArray;
> > >                   } 
> > >                   public function filterAuthorsGrid():void
> > >                   {
> > >                           Alert.show(this.toString() 
> > > +" : "+authorsDataProvider)
> > >                   
> > >   //authorsDataProvider.filterFunction=authorsStatusFilter;    
> > >            
> > >                           //authorsDataProvider.refresh();
> > >                   }
> > >                   public function authorsStatusFilter
> > > (item:Object):Boolean       
> > >                   {               
> > >                           if 
> > > (cboAuthorsStatusFilter.selectedItem != "All")               
> > >                           {                       
> > >                                   return item.status == 
> > > cboAuthorsStatusFilter.selectedItem; 
> > >                           } else {
> > >                                   return true;               
> > >                           } 
> > >                           //return true;     
> > >                   }
> > >                   
> > > 
> > >               ]]>
> > >   </mx:Script>
> > > </mx:ComboBox>
> > > 
> > > </mx:HBox>
> > > 
> > > 
> > > --- In flexcoders@yahoogroups.com, "sanjaypmg" <sanjaypmg@> 
> wrote:
> > > >
> > > > Thanks Phil,
> > > > .... :) That's what I was looking for...Now I'll try to 
> convert it 
> > > > into Flex2.0.
> > > > 
> > > > Wish me luck.... ;)
> > > > 
> > > > Thanks,
> > > > Sanjay
> > > > 
> > > > --- In flexcoders@yahoogroups.com, "phipzkillah" <pkrasko@> 
> wrote:
> > > > >
> > > > > I am also looking for this functionality.  About a month 
ago 
> I 
> > > came
> > > > > across this page
> > > > > <http://www.cflex.net/showFileDetails.cfm?
> > > > ObjectID=299&Object=File&Chann\
> > > > > elID=1> .  It is a sample of a datagrid whose headers have 
a 
> > > drop 
> > > > down
> > > > > list to filter each field/column on.  Unfortuneately it 
was 
> > > > developed in
> > > > > Flex 1.5.  Has anyone converted it to Flex 2.0?  If so, 
this 
> is 
> > > the
> > > > > answer we all are looking for.
> > > > > 
> > > > > If someone can copy that source code and eliminate the 
> compiler 
> > > > errors
> > > > > you will be doing several of us a huge favor!
> > > > > 
> > > > > Thanks
> > > > > 
> > > > > Phil
> > > > > 
> > > > > --- In flexcoders@yahoogroups.com, "sanjaypmg" 
<sanjaypmg@> 
> > > wrote:
> > > > > >
> > > > > > Hi There,
> > > > > >
> > > > > > Is there any way to put filters feature on Datagrid as 
> > > available 
> > > > in
> > > > > > Excel?
> > > > > >
> > > > > > Or
> > > > > >
> > > > > > Anything Similar to that feature?
> > > > > >
> > > > > > Please let me know if there is something or any possible 
> > > > solution for
> > > > > > the same.
> > > > > >
> > > > > > Thanks
> > > > > > Sanjay sharma
> > > > > >
> > > > >
> > > >
> > >
> >
>


Reply via email to