5

I need to merge the cells as shown in the picture:

enter image description here

Neeraj Gulia
  • 640
  • 8
  • 24

1 Answers1

3

Flex (in my understanding) does not directly provide this. You have a few options.

Either way, you may need to arrange your data in a hierarchical model. (Parent with 3 children appears to describe your question)

The first option I see would involve directly declaring your data as hierarchical to the advanceddatagrid. If you search for hierarchical advanceddatagrid you should be able to find tutorials online.

Alternatively, you may desire to always have the data show, and not only when you expand the parent. In this case, you will still need the hierarchical model, but you will have to create a custom itemrenderer able to represent all of the children data for one parent object. (an itemrenderer with three labels in a VBox/VGroup would work for the example you've given)

If these don't help, or you would like more detail on one solution or the other, feel free to ask in a comment.

EDIT::

As an example of the itemrenderer, here's the source of a similar itemrenderer I've used. (mine only populates two labels, but you should be able to extend it if you understand what it's doing)

<VBox xmlns:mx="http://www.adobe.com/2006/mxml" 
    implements="mx.controls.listClasses.IDropInListItemRenderer"
    width="100%" height="100%" 
    verticalGap="0" paddingTop="5" paddingBottom="5" 
    horizontalScrollPolicy="off"
    horizontalAlign="center">

    <mx:Script>
        <![CDATA[
            import mx.controls.Label;
            import mx.controls.dataGridClasses.DataGridListData;
            import mx.controls.listClasses.BaseListData;

            private var _listData:BaseListData;

            [Bindable("dataChange")]

            // Define the getter method.
            public function get listData():BaseListData
            {
                return _listData;
            }
            // Define the setter method,
            public function set listData(value:BaseListData):void
            {
                _listData = value;
            }

        override public function set data(value:Object):void
        {
            removeAllChildren();

            if (value != null)
            {
                var myListData:DataGridListData = DataGridListData(listData);

                var lLabel1:Label = new Label();
                var lLabel2:Label = new Label();


                lLabel1.text = value[myListData.dataField][0];
                lLabel1.percentWidth = 0;
                addChild(lLabel1);

                lLabel2.text = value[myListData.dataField][1];
                lLabel2.percentWidth = 0;
                addChild(lLabel2);
            }

        } 
        ]]>
    </mx:Script>
</VBox>

I removed a lot of proprietary code, so if it doesn't make any sense let me know.

This is intended to be reusable, hence the value[myListData.dataField], but if you want you can easily make it a lot more specific by defining the fields yourself. This particular code expects the data in the following format, for example:

value[field][0] = "text1";
value[field][1] = "text2";

Object has:

var field:Array = [];

field[0] = "text1";
field[1] = "text2";
Sam DeHaan
  • 10,246
  • 2
  • 40
  • 48
  • 3
    +1 The only way to get the functionality you're looking for is to use an `AdvancedDataGrid` with `HierarcichalData`. – Jason Towne Aug 02 '11 at 15:05
  • The suggestion is good, but I need to show some vertical text in the merged cells, I am wondering would I be able to use itemRenderer in this case. – Neeraj Gulia Aug 03 '11 at 06:14
  • 1
    I attached some example code, @Mr. G. Let me know if that helps or if you'd like a bit more. – Sam DeHaan Aug 03 '11 at 13:06
  • I really very much appreciate your help here @samdehaan, but the snippet that you have shared is actually representing two data in one cell, while I want to merge three or more cells vertically. I have provided your answer an upvote :) – Neeraj Gulia Aug 04 '11 at 05:01
  • Yes. The implementation using this kind of itemRenderer woult require you to consolidate your data into a Collection of subcollections, where each subcollection would be a single item of the original data set. I can add a bit of code in a little bit to represent how this would work. – Sam DeHaan Aug 04 '11 at 12:08