0

您好我在渲染后遇到火花数据网格列中的数据对齐问题。所有标题都向左对齐,但是我想做以下 1. 列标题名称的中间。2. 将文本右对齐。3.冻结第一列,这样当我进行水平滚动时,第一列不应该水平移动。

在这方面的任何帮助将不胜感激。

谢谢并恭祝安康

<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                    xmlns:s="library://ns.adobe.com/flex/spark" 
                    xmlns:mx="library://ns.adobe.com/flex/mx"
                    clipAndEnableScrolling="true">

    <fx:Script>
        <![CDATA[
            import flashx.textLayout.formats.BackgroundColor;

            import mx.controls.Alert;
            import mx.states.SetStyle;

            private const POSITIVE_COLOR:uint = 0x000000; // Black
            private const NEGATIVE_COLOR:uint = 0xFF0000; // Red

            override public function prepare(hasBeenRecycled:Boolean):void {

                if (this.data) {
                    if (column.labelFunction != null ) {
                        lblData.text = column.labelFunction( data, column );

                        setStyle("color", (parseInt(this.data.st1) < 0) ? NEGATIVE_COLOR : POSITIVE_COLOR);

                    } else {
                        lblData.text = data[column.dataField];
                    }
                }
            }
        ]]>
    </fx:Script>

    <s:Label id="lblData" top="9" left="7" textAlign="right"/>

</s:GridItemRenderer>
4

1 回答 1

2

2/ Align the text to right.

I'll start with the easiest one.
In your custom item renderer, you're still aligning to the left (left="7"). You have two options to fix this:

<s:Label id="lblData" top="9" right="7"/>

will align the Label to the right and cause text overflow to the left

<s:Label id="lblData" top="9" left="7" right="7" textAlign="right"/>

will make the Label take all the available space, align the text to the right and truncate the text if it's too big

1/ Middle the column header name.

I think the only way is to create a custom headerRenderer.

  • copy the entire DefaultGridHeaderRenderer
  • find the Label with id "labelDisplay"
  • change its textAlign property to center
  • assign the custom headerRenderer:
    <s:GridColumn headerRenderer="path.to.CenteredHeaderRenderer"/>

3/ Freeze the first column so that when i do horizontal scroll, the first column should not move horizontally.

I'm afraid this is going to require some serious hacking. If you don't want to dive in and create a customized DataGrid, I think your best bet is to fake it:

  • create a List to represent the fixed column
  • create a DataGrid to represent the other columns
  • turn off the List's vertical scrollbar: you wanna controll the scrolling through the grid
  • bind their vertical scrolling position: when the DataGrid is vertically scrolled, the List must follow and vice-versa
  • bind their selected items
  • do some skinning to make it look like one DataGrid
于 2013-04-26T10:32:43.330 回答