Menu

Data Grid Skin

SourceForge Editorial Staff
There is a newer version of this page. You can find it here.

[[ style ]]
h3
.indent blockquote
[[ /style ]]

# Spark DataGrid Skin - Functional and Design Specification ---- ### Introduction The DataGrid skin is the container for the DataGrid's Grid and GridColumnHeaderGroup. The default DataGrid skin adds a Scroller, which enables interactive scrolling with scrollbars, a border, and a horizontal separator between the Grid and the GridColumnHeaderGroup. ### DataGrid Skin Parts API Description All of the DataGrid's visual elements, except for the header and item renderers, are optional skin parts. The type of nearly all of the skin parts is IFactory, not because they are "dynamic" skin parts, but just because the corresponding visual elements are created as needed. Nearly all of the DataGrid skin parts are backed by eponymous Grid properties, for example the DataGrid caretIndicator skin part is used to set the grid skin part's caretIndicator property. The caretIndicator, hoverIndicator, selectionIndicator, columnSeparator, rowSeparator, and headerColumnSeparator skin parts are factories for IVisualElemements. Typically they are specified with GraphicElement classes, for example: <fx:declarations> <fx:component id="caretIndicator"> <s:rect> <s:stroke> <s:solidcolorstroke color="0x0167FF" weight="1"> </s:solidcolorstroke></s:stroke> </s:rect> </fx:component> </fx:declarations> The rowBackground skin part defines the visual element that appears behind each row. It's often useful for this element's appearance to depend on the row it's displayed for. Row background elements that implement IGridRowBackground can use the row index or corresponding grid dataProvider item to configure themselves. The initializeRowBackground() method is called before the rowBackground visual element is displayed. The example below demonstrates how a rowBackground visual element that implements IGridRowBackground can be defined to render alternating row color backgrounds. Note that this common case is already supported in a more general way by the DataGrid alternatingRowColors style, more on that below. <fx:declarations> <fx:component id="rowBackground"> <s:rect implements="spark.components.IGridRowBackground"> <s:fill> <s:solidcolor id="rowBackgroundFillColor" color="0xFFFFFF"> </s:solidcolor></s:fill> <fx:script> </fx:script> </s:rect> </fx:component> </fx:declarations> The alternatingRowColorsBackground skin part is only use when the DataGrid alternatingRowColorStyle is defined. If alternatingRowColorStyle is specified then the alternatingRowColorsBackground skin part is used as the value of the Grid rowBackground property. If both rowBackground skin part was specified, it's overidden. In the subset of the DataGrid API presented below, all of the public vars are optional (required="false") skin parts and they're all bindable. The SkinPart and Bindable metadata has been elided to make the code easier to read. package spark.components { public class DataGrid extends SkinnableContainerBase implements IFocusManagerComponent { /** * The IVisualElement class used to render the alternatingRowColors style */ public var alternatingRowColorsBackground:IFactory; /** * The IVisualElement class used to render the grid's caret indicator. */ public var caretIndicator:IFactory; /** * A reference to the GridColumnHeaderGroup that displays the column headers. */ public var columnHeaderGroup:GridColumnHeaderGroup; /** * The IVisualElement class used to render the vertical separator between columns. */ public var columnSeparator:IFactory; /** * The container for the itemEditor visual element. */ public var itemEditorLayer:IVisualElementContainer; /** * A reference to the Grid that displays the dataProvider. */ public var grid:spark.components.Grid; /** * The IVisualElement class used to provide hover feedback. */ public var hoverIndicator:IFactory; /** * The IVisualElement class used to render the background of each row. */ public var rowBackground:IFactory; /** * The IVisualElement class used to render the horizontal separator between header rows. */ public var rowSeparator:IFactory; /** * A reference to the Scroller that scrolls the grid. */ public var scroller:Scroller; /** * The IVisualElement class used to render selected rows or cells. */ public var selectionIndicator:IFactory; //... Remaining Grid API appears elsewhere in this spec } } ### DataGridSkin API Description The current default DataGridSkin follows. Note that one need not copy the entire default skin to create a version that's configured with different visual elements. In MXML, subclass fx:Declarations override the values of declarations from the super class. So in many cases one can customize the default DataGrid skin by defining a subclass of DataGridSkin and specifying new values of visual elements. For example, to create a version of DataGridSkin that specifies a different visual element as the rowSeparator skin part, one could just write: <spark:datagridskin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"> <fx:declarations> <fx:component id="rowSeparator"> <s:line> <s:stroke> <s:lineargradientstroke rotation="45" weight="5" caps="square"> <s:gradiententry color="haloBlue"> <s:gradiententry color="haloGreen"> </s:gradiententry></s:gradiententry></s:lineargradientstroke> </s:stroke> </s:line> </fx:component> </fx:declarations> </spark:datagridskin> The default DataGrid skin (below) defines a value for all of the skin parts except rowBackground. <s:sparkskin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:fb="http://ns.adobe.com/flashbuilder/2009" alpha.disabled="0.5" minwidth="89" minheight="84"> <fx:metadata> HostComponent("spark.components.DataGrid") </fx:metadata> <s:states> <s:state name="normal"> <s:state name="disabled"> </s:state></s:state></s:states> <fx:declarations> <fx:component id="alternatingRowColorsBackground"> <s:rect implements="spark.components.IGridRowBackground"> <fx:script> ... code elided for clarity ... </fx:script> <s:fill> <s:solidcolor id="rowBackgroundFillColor" color="0xFFFFFF"> </s:solidcolor></s:fill> </s:rect> </fx:component> <fx:component id="caretIndicator"> <s:rect> <s:stroke> <s:solidcolorstroke color="0x0167FF" weight="1"> </s:solidcolorstroke></s:stroke> </s:rect> </fx:component> <fx:component id="columnSeparator"> <s:line> <s:stroke> <s:solidcolorstroke color="0xE6E6E6" weight="1" caps="square"> </s:solidcolorstroke></s:stroke> </s:line> </fx:component> <fx:component id="headerColumnSeparator"> <s:line> <s:stroke> <s:solidcolorstroke color="0x696969" weight="1" caps="square"> </s:solidcolorstroke></s:stroke> </s:line> </fx:component> <fx:component id="headerRenderer"> <s:defaultgridheaderrenderer> <s:sortindicator> <fx:component> <s:path data="M 3.5 7.0 L 0.0 0.0 L 7.0 0.0 L 3.5 7.0"> <s:fill> <s:radialgradient rotation="90" focalpointratio="1"> <s:gradiententry id="arrowFill1" color="0" alpha="0.6"> <s:gradiententry id="arrowFill2" color="0" alpha="0.8"> </s:gradiententry></s:gradiententry></s:radialgradient> </s:fill> </s:path> </fx:component> </s:sortindicator> </s:defaultgridheaderrenderer> </fx:component> <fx:component id="hoverIndicator"> <s:rect> <s:fill> <s:solidcolor color="0xCEDBEF"> </s:solidcolor></s:fill> </s:rect> </fx:component> <fx:component id="rowSeparator"> <s:line> <s:stroke> <s:solidcolorstroke color="0xE6E6E6" weight="1" caps="square"> </s:solidcolorstroke></s:stroke> </s:line> </fx:component> <fx:component id="selectionIndicator"> <s:rect> <s:fill> <s:solidcolor color="0xA8C6EE"> </s:solidcolor></s:fill> </s:rect> </fx:component> <fx:component id="editorIndicator"> <s:rect> <s:fill> <s:solidcolor color="0xFFFFFF"> </s:solidcolor></s:fill> </s:rect> </fx:component> </fx:declarations> <s:rect id="background" left="1" right="1" top="1" bottom="1"> <s:fill> <s:solidcolor id="bgFill" color="0xFFFFFF"> </s:solidcolor></s:fill> </s:rect> <s:vgroup horizontalalign="justify" gap="0" left="0" right="0" top="0" bottom="0"> <s:gridcolumnheadergroup id="columnHeaderGroup" paddingleft="1" paddingtop="1" paddingright="1" columnseparator="{headerColumnSeparator}" headerrenderer="{headerRenderer}"> <s:vgroup horizontalalign="justify" height="100%" gap="-1"> <s:line id="headerSeparator"> <s:stroke> <s:solidcolorstroke color="0x696969" weight="1" caps="square"> </s:solidcolorstroke></s:stroke> </s:line> <s:scroller id="scroller" minviewportinset="1" hasfocusablechildren="false" height="100%"> <s:grid id="grid" itemrenderer="spark.skins.spark.DefaultGridItemRenderer"> <s:gridlayer s:id="backgroundLayer"> <s:gridlayer s:id="selectionLayer"> <s:gridlayer s:id="editorIndicatorLayer"> <s:gridlayer s:id="rendererLayer" root="{grid}"> <s:gridlayer s:id="overlayLayer"> </s:gridlayer></s:gridlayer></s:gridlayer></s:gridlayer></s:gridlayer></s:grid> </s:scroller> </s:vgroup> </s:gridcolumnheadergroup></s:vgroup> <s:rect left="0" right="0" top="0" bottom="0" id="border"> <s:stroke> <s:solidcolorstroke id="borderStroke" weight="1"> </s:solidcolorstroke></s:stroke> </s:rect> <s:group id="itemEditorLayer" includeinlayout="false" visible="false"> </s:group></s:sparkskin>
[[ include ref='flexsdk_rightnav' ]]
[[ include ref='site:open_commentlogin' ]]

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.