Thanks Meena,
                            Can u send me the whole code what u have.I need
urgently.

Thanks & Regards,
Srinivas.

On Tue, Mar 17, 2009 at 4:55 PM, Meenakshi H <[email protected]>wrote:

> hi Vasu,
>
> i have a same requirement..
> i have wriitten sum custom component, hope this will solve..
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml";
> liveScrolling="false"  headerRelease="{stopEvent(event)}"
> allowMultipleSelection="true" allowDragSelection="true"
> creationComplete="initComp()">
>  <!-- Selected Column -->
>  <mx:DataGridColumn id="selectColumn"  minWidth="25"  width="25"
> dataField="prototype" editable="false"  resizable="false">
>     <mx:itemRenderer>
>        <mx:Component>
>          <mx:Canvas width="100%"  height="100%">
>            <mx:CheckBox x="4" focusEnabled="false" id="selectedBox"
> mouseEnabled="false" keyUp="{outerDocument.KeyUpEvent(event, data,
> (selectedBox))}"
> selected="{outerDocument.isSelected(data,outerDocument.selectedItems)}"/>
>        </mx:Canvas>
>        </mx:Component>
>     </mx:itemRenderer>
>     <mx:headerRenderer>
>       <mx:Component>
>        <mx:Canvas width="100%" visible="{outerDocument.getHeaderChkBox()}"
> height="100%" click="{outerDocument.headerCheckboxClicked(event)}">
>
>         <mx:CheckBox x="4" id="headerCheckbox" mouseEnabled="false"
> selected="{outerDocument.allItemsSelected(outerDocument.selectedItems)}"
> keyUp="{outerDocument.HeaderCheckBoxKeyUpEvent(event,(headerCheckbox))}"/>
>
>        </mx:Canvas>
>       </mx:Component>
>     </mx:headerRenderer>
>  </mx:DataGridColumn>
>  <mx:Script>
>   <![CDATA[
>    import mx.events.ResizeEvent;
>    import mx.collections.XMLListCollection;
>    import mx.collections.ArrayCollection;
>    import mx.core.EventPriority;
>    import mx.events.ListEvent;
>    import mx.controls.Alert;
>    import mx.containers.Canvas;
>    import mx.core.ComponentDescriptor;
>    import mx.controls.listClasses.IListItemRenderer;
>    import mx.events.DataGridEvent;
>    import mx.controls.CheckBox;
>    import mx.collections.ListCollectionView;
>    public var _showChkBoxHeader:Boolean=true;
>    public var _onclickHeaderCheckBox:Function;
>    [Bindable]
>    public var enableCopy : Boolean = true;
>    private var copyContextItem:ContextMenuItem;
>    private var dataToCopy:String = '';
>    override public function set columns(value:Array):void
>    {
>     var newColumns:Array = value.slice();
>     if(newColumns.indexOf(selectColumn) == -1)
>     {
>      newColumns.unshift(selectColumn);
>     }
>     super.columns = newColumns;
>    }
>
>    override protected function
> selectItem(item:IListItemRenderer,shiftKey:Boolean,
> ctrlKey:Boolean,transition:Boolean = true):Boolean
>    {
>     //Check to see if the select is from the Checkbox row, all the others
> will have a listData property
>     if(!(item as Object).hasOwnProperty("listData") && !shiftKey)
>     {
>      ctrlKey = true;
>      return super.selectItem(item, shiftKey, ctrlKey, transition);
>     }
>     return false;
>    }
>
>    // fake all keyboard interaction as if it had the ctrl key down
>    override protected function keyDownHandler(event:KeyboardEvent):void
>    {
>     // this is technically illegal, but works
>     event.ctrlKey = true;
>     event.shiftKey = false;
>     super.keyDownHandler(event);
>    }
>    // fake all keyboard interaction as if it had the ctrl key down
>    public function KeyUpEvent(event:KeyboardEvent, data:Object,
> obj:CheckBox):void
>    {
>     if(event.keyCode == 32 ){
>      if(obj.selected) {
>       obj.selected=true;
>      }
>      else{
>       obj.selected=false;
>      }
>      var item:IListItemRenderer = itemToItemRenderer(data);
>      //Alert.show(obj.tabIndex + "");
>      super.selectItem(item, false, true, true);
>     }
>    }
>
>
>    public function isSelected(data:Object, selectedItems:Array):Boolean
>    {
>     return isItemSelected(data);
>    }
>
>    public function headerCheckboxClicked(event:Event):void
>    {
>        //Either select or deselect all the rows
>        if((dataProvider as ListCollectionView).length > 0) {
>         if(allItemsSelected())
>         {
>          //Clear all selected items
>          selectedItems = new Array();
>         }
>         else
>         {
>          //Select the entire grid
>          if(dataProvider is ListCollectionView)
>          {
>           selectedItems = (dataProvider as ListCollectionView).toArray();
>          }
>         }
>         if(_onclickHeaderCheckBox!=null){
>          if(allItemsSelected())
>           _onclickHeaderCheckBox(true);
>          else
>           _onclickHeaderCheckBox(false);
>         }
>        }
>    }
>    // 32 is space bar key code.
>       public function HeaderCheckBoxKeyUpEvent(event:KeyboardEvent,
> obj:CheckBox):void{
>        if((dataProvider as ListCollectionView).length == 0 && event.keyCode
> == 32 ){
>         obj.selected=false;
>        }
>       }
>
>       public function allItemsSelected(items:Array = null):Boolean
>    {
>      if(dataProvider is ListCollectionView)
>     {
>      if((dataProvider as ListCollectionView).length > 0)
>      {
>       return selectedItems.length == (dataProvider as
> ListCollectionView).length;
>      }
>     }
>     return false;
>    }
>
>    public function stopEvent(event:DataGridEvent):void
>    {
>     if(columns[event.columnIndex] == selectColumn)
>     {
>      event.stopImmediatePropagation();
>      event.preventDefault();
>     }
>    }
>
>    override protected function createChildren():void{
>     super.createChildren();
>     if(enableCopy){
>      createContextMenu();
>
> this.addEventListener(ListEvent.ITEM_ROLL_OVER,copyAllMenuHandler,false,
> EventPriority.DEFAULT);
>        }
>    }
>
>
>    private function initComp():void{
>     selectColumn.width=25;
>    }
>
>
>    private function createContextMenu():void {
>          copyContextItem = new ContextMenuItem("Copy All");
>
> copyContextItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,copyAllDataHandler);
>
>               copyContextItem.enabled = true;
>       contextMenu = new ContextMenu();
>       contextMenu.customItems = [copyContextItem];
>       //comment the following line if you want default items in context
> menu.
>       contextMenu.hideBuiltInItems();
>    }
>
>    private function copyAllDataHandler(event:Event):void {
>     if(dataToCopy!=null){
>        System.setClipboard(dataToCopy);
>      }
>    }
>
>       private function copyAllMenuHandler(event:ListEvent):void {
>        var dgc:DataGridColumn =
> event.currentTarget.columns[event.columnIndex] as DataGridColumn;
>        var colDataField:String = dgc.dataField;
>     var rowIndex:int = event.rowIndex;
>     var obj:Object=null;
>     if(rowIndex > 0){
>      if((event.currentTarget as CheckBoxDataGrid).dataProvider is
> ArrayCollection){
>       var ac:ArrayCollection = (event.currentTarget as
> CheckBoxDataGrid).dataProvider as ArrayCollection;
>       if(ac!=null){
>         if(ac.length > 0 && rowIndex <= ac.length)
>        obj = ac.getItemAt(rowIndex-1);
>       }
>      }else if((event.currentTarget as CheckBoxDataGrid).dataProvider is
> XMLListCollection){
>       var xmlLC:XMLListCollection = (event.currentTarget as
> CheckBoxDataGrid).dataProvider as XMLListCollection;
>       if(xmlLC!=null){
>        if(xmlLC.length>0)
>        obj = xmlLC.getItemAt(rowIndex-1);
>       }
>      }
>      if(obj!=null)
>       dataToCopy = obj[colDataField];
>        }
>       }
>
>
>    public function getHeaderChkBox():Boolean{
>     return _showChkBoxHeader;
>    }
>    public function set showChkBoxHeader(chkVal:Boolean):void{
>     _showChkBoxHeader=chkVal;
>    }
>    //Getting Header check Box onclick event
>    public function getOnclickHeaderCheckBox():Function{
>     return _onclickHeaderCheckBox;
>    }
>    //Setting Header check Box onclick event
>    public function set onclickHeaderCheckBox(onclickFun:Function):void{
>     _onclickHeaderCheckBox=onclickFun;
>    }
>
>   ]]>
>  </mx:Script>
>
> </mx:DataGrid>
>
>
> Regards,
> Meena
>
> On Sat, Mar 14, 2009 at 11:02 AM, Vasu <[email protected]> wrote:
>
>>
>>
>>        I have a DataGrid with five columns first one for checkboxes(In
>> header,item),second one for Id,third one for Name,fourth one for phone
>> number and final column is email address.
>>
>>  In first column of my DataGrid,i have two Renderers one is
>> HeaderRenderer and other one is ItemRenderer for the same column with
>> checkboxes.
>> I'm writing script there only for header checkbox(Id is chkAll) and
>> item renderer checkbox(Id is chk).If i select the header checkbox,all
>> the item renderer checkboxes are also selected and if i deselect the
>> header checkbox then deselect the all itemrenderer checkboxes.
>>
>> After selecting the checkBox(it may be one (or) All) i need to the
>> data from the datagrid by using the button(Delete).
>>
>> How to do that?
>>
>> Here am sending the code also,
>> <?xml version="1.0" encoding="utf-8"?>
>> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
>> layout="absolute">
>>
>>        <mx:Script>
>>                <![CDATA[
>>                        import mx.collections.ArrayCollection;
>>
>>                        [Bindable]
>>            public var arr:ArrayCollection = new ArrayCollection();
>>                ]]>
>>        </mx:Script>
>>        <mx:XMLList id="employees">
>>        <employee>
>>                <id>111</id>
>>            <name>Christina Coenraets</name>
>>            <phone>555-219-2270</phone>
>>            <email>http://www.yahoo.com</email>
>>            <active>true</active>
>>        </employee>
>>        <employee>
>>                <id>222</id>
>>            <name>Joanne Wall</name>
>>            <phone>555-219-2012</phone>
>>            <email>http://www.gmail.com</email>
>>            <active>true</active>
>>        </employee>
>>        <employee>
>>                <id>333</id>
>>            <name>Maurice Smith</name>
>>            <phone>555-219-2012</phone>
>>            <email>http://www.rediffmail.com</email>
>>            <active>false</active>
>>        </employee>
>>        <employee>
>>                <id>444</id>
>>            <name>Mary Jones</name>
>>            <phone>555-219-2000</phone>
>>            <email>[email protected]</email>
>>            <active>true</active>
>>        </employee>
>>    </mx:XMLList>
>>
>>        <mx:VBox width="100%" height="100%">
>>                <mx:DataGrid id="dg" width="100%" height="60%" rowCount="5"
>> dataProvider="{employees}">
>>                        <mx:columns>
>>                <mx:DataGridColumn sortable="false">
>>                        <mx:headerRenderer>
>>                                <mx:Component>
>>                                        <mx:HBox>
>>                                                <mx:Script>
>>                                                        <![CDATA[
>>                                                                import
>> mx.controls.Alert;
>>                                                        ]]>
>>                                                </mx:Script>
>>                                                <mx:CheckBox id="chkAll"
>> click="Alert.show('hi')"/>
>>                                        </mx:HBox>
>>                                </mx:Component>
>>                        </mx:headerRenderer>
>>                        <mx:itemRenderer>
>>                                <mx:Component>
>>                                        <mx:HBox>
>>                                                <mx:Script>
>>                                                        <![CDATA[
>>                                                                import
>> mx.collections.ArrayCollection;
>>                                                                import
>> mx.controls.Alert;
>>                                                                /*
>> [Bindable]
>>                                                                private var
>> arr:ArrayCollection = new
>> ArrayCollection(); */
>>                                                                private
>> function getData():void {
>>
>>
>>  if(chk.selected)
>>                                                                        {
>>
>>                      outerDocument.arr.addItem
>> (outerDocument.dg.selectedItem.id<http://outerdocument.dg.selecteditem.id/>
>> );
>>
>>                      Alert.show("array:"+outerDocument.arr);
>>                                                                        }
>>
>>  else
>>                                                                        {
>>
>>      for(var i:uint = 0;i<outerDocument.arr.length; i+
>> +)
>>
>>      {
>>
>>              if((outerDocument.arr.getItemAt(i)) ==
>> (outerDocument.dg.selectedItem.id<http://outerdocument.dg.selecteditem.id/>
>> ))
>>
>>              {
>>
>>                      outerDocument.arr.removeItemAt(i);
>>
>>
>>              }
>>
>>      }
>>
>>      Alert.show("array:"+outerDocument.arr);
>>                                                                        }
>>                                                                }
>>                                                        ]]>
>>                                                </mx:Script>
>>
>>                                                <mx:CheckBox id="chk"
>> click="getData()"/>
>>                                        </mx:HBox>
>>                                </mx:Component>
>>                        </mx:itemRenderer>
>>                </mx:DataGridColumn>
>>                <mx:DataGridColumn dataField="id" headerText="Id"
>> visible="false"/>
>>                <mx:DataGridColumn dataField="name" headerText="Name"/
>> >
>>                <mx:DataGridColumn dataField="phone"
>> headerText="Phone"/>
>>                <mx:DataGridColumn dataField="email"
>> headerText="Email"/>
>>            </mx:columns>
>>        </mx:DataGrid>
>>
>>        <mx:Form width="100%" height="100%">
>>            <mx:FormItem label="Name">
>>                <mx:Label 
>> text="{dg.selectedItem.name<http://dg.selecteditem.name/>
>> }"/>
>>            </mx:FormItem>
>>            <mx:FormItem label="Email">
>>                <mx:Label text="{dg.selectedItem.email}"/>
>>            </mx:FormItem>
>>            <mx:FormItem label="Phone">
>>                <mx:Label text="{dg.selectedItem.phone}"/>
>>            </mx:FormItem>
>>        </mx:Form>
>>        </mx:VBox>
>>
>> </mx:Application>
>>
>> Thanks & Regards,
>> Srinivas.
>>
>> >>
>>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to