Como aplicar a formatação para alimentação de dados AdvancedDATAGRID no ActionScript 3.0
-
16-11-2019 - |
Pergunta
Estou usando o componente Halo AdvancedDateGrid, no qual o itemEditor padrão para cada coluna é mx.controls.textInput.
Por exemplo, o provedor de dados é: [Código] [Bindable] Private Var LabelsGriverAray: Array= [{Tag: "Apple"}, {Tag: "* Banana"}, {Tag: "Cenoura"}]; [/ código] E a definição AdvancedDateGrid é: [Código] [/ código]
Se uma string da matriz DataProvider for precedida por um asterisco - como é o caso da banana neste exemplo - a string precisa ser cercada por colchetes e ser exibido em uma cor cinza.
Eu tentei fazer o seguinte: [CÓDIGO]
Um colega me contou sobre o uso do atributo LabelFunction do AdvancedDateGridColumn. Eu tentei isso, mas não consegui fazer a seguinte tarefa (o ID da coluna é 'Tag'): [Código] tag.itemeditor.htmltext= formattedtext; [/ código]
Eu recebo erro "Acesso de propriedade possivelmente indefinida HTMLText através de uma referência com o tipo estático MX.Core: Ifactory.
Eu tentei extrair explicitamente o itemEditor de texto (como eu fiz para os dados do conjunto de substituição) e usei a labelfunction, mas não consegui ficar nos escopos corretos.
Sua ajuda é muito apreciada, Bonnie
Solução
Try creating your own itemRenderer / itemEditor.
This would be your datagrid:
<fx:Script>
<![CDATA[
[Bindable] private var labelsGridArray:Array = [ { tag:"apple" }, { tag:"*banana" }, { tag:"carrot" } ];
]]>
</fx:Script>
<mx:DataGrid dataProvider="{labelsGridArray}" >
<mx:columns>
<mx:DataGridColumn headerText="Name" itemRenderer="NameItemRenderer"/>
</mx:columns>
</mx:DataGrid>
And this would be your itemRenderer/editor (NameItemRenderer.mxml)
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true">
<fx:Script>
<![CDATA[
override public function set data(value:Object):void{
super.data = value;
if(value.tag.indexOf("*")!= -1){
lblData.text = "[" + value.tag + "]";
lblData.setStyle("color",0xFF0000);
}
else{
lblData.text = "" + value.tag ;
lblData.setStyle("color",0x000000);
}
}
]]>
</fx:Script>
<s:Label id="lblData" top="0" left="0" right="0" bottom="0"/>
I have used a normal mx:Datagrid and a spark MXDataGridItemRenderer for this, but the way it works will be the same for the AdvancedDataGrid. All you need to do is override set data()
Cheers