Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex DataGrid with row number column

Tags:

apache-flex

I want to extend the DataGrid component so that there is a (read-only) column for the row number like you see in spreadsheets. I came across this article http://www.cflex.net/showFileDetails.cfm?ObjectID=735 but it depends on the data being unique for each row so that it can index into the array. If the data is not unique (like for an empty grid) it doesn't work. How can I implement that?

like image 422
philcruz Avatar asked Jan 22 '26 02:01

philcruz


1 Answers

This worked for me:

<mx:Label xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
    <![CDATA[
        import mx.controls.AdvancedDataGrid;

        private var handleDataChangedEnabled:Boolean = false;

        override public function set data(value:Object):void {
            super.data = value;

            if (!handleDataChangedEnabled) {
                addEventListener("dataChange", handleDataChanged);
            }
        }

        public function handleDataChanged(event:Event):void {
            this.text = String(listData.rowIndex + (listData.owner as AdvancedDataGrid).verticalScrollPosition + 1);
        }
    ]]>
</mx:Script>

Of course, you would have to change AdvancedDataGrid to DataGrid.

Cheers.

like image 93
Matt Avatar answered Jan 25 '26 06:01

Matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!