Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > Flash/Flex > Flex
Flex Forum d'entraide sur la programmation Adobe Flex : applications Internet riches (RIA)
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 11/05/2011, 12h29   #1
Membre à l'essai
 
Inscription : octobre 2007
Messages : 79
Détails du profil
Informations forums :
Inscription : octobre 2007
Messages : 79
Points : 22
Points : 22
Par défaut Dataprovider dans une dataGrid personnalisé

Bonjour,
mon probleme c'est que aprés la personnalisation du column d'une datagrid,j'ai rencontré un probleme avec datagrid si la list passé est de type ArrayCollection par contre ça marche avec Array!!
si je fait:
dataProvider="{gridData}" ça marche
dataProvider="{listEnum}" ça marche pas!
voici mon code:
test.mxml
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml"
		   layout="absolute"
		   width="100%"
		   height="100%" xmlns:component="ma.cnss.portal.gui.module.fse.view.component.*" xmlns:component1="ma.cnss.portal.gui.module.main.view.component.*">
			<mx:Script>
				<![CDATA[
					import mx.controls.Alert;
					import mx.controls.dataGridClasses.DataGridColumn;
					import mx.collections.ArrayCollection;
					[Bindable]
					public var listLigneActeMed:ArrayCollection;	
					private function displayMantant(item:Object, col:DataGridColumn):String
					{
					     return formatNumber.numberFormatter.format(item.prixActe*item.qteActe);
					}
					private function displayPrix(item:Object, col:DataGridColumn):String
					{
					     return formatNumber.numberFormatter.format(item.prixActe);
					}
					private function Alerter():void{
 
					Alert.show("etat: "+dg.selectedItem.etat,"   Etat de l'acte");
 
					}
					private function getRowBackgroundColor(item:Object):uint{
                       return 0xf2092a;
                     }
 
                    private function buildToolTip(item:Object):String{
                      var myString:String = "";
                      if(item.etat=="ERROR")
                          {
                           //  myString = myString + "Vous avez un " + item.messsage + "\n";
                           myString = myString + "Vous avez un \n";
                           }
                              return myString;
                                        } 
				]]>
			</mx:Script>
	<component1:FormatNumber id="formatNumber" visible="false" height="0"/>
	<mx:VBox width="100%" height="100%">
 
 
 
		<mx:HBox width="100%" paddingLeft="10" paddingRight="10" height="100%">
			<component:DataGridEx id="dg"
						 width="100%"
						 dataProvider="{listLigneActeMed}"
						 rowCount="2"
						 height="100%" variableRowHeight="true" itemClick="Alerter()" rowBackgroundColorFunction="getRowBackgroundColor">
				<component:columns>
					<component:NestedDataGridColumn headerText="Libelle acte" nestedDataField="acte.nom" width="110" wordWrap="true"/>
					<component:NestedDataGridColumn headerText="Code acte" nestedDataField="acte.code" width="110" wordWrap="true"/>
					<mx:DataGridColumn headerText="Cotation NGAP"
									   dataField="ngap"
									   width="100" wordWrap="true"/>
					<mx:DataGridColumn headerText="Prix"
									   labelFunction="displayPrix"
									   width="80" textAlign="right" showDataTips="true"/>
					<mx:DataGridColumn headerText="Quantité"
									   dataField="qteActe"
									   width="80" textAlign="right" showDataTips="true"/>
					<mx:DataGridColumn headerText="Montant"	labelFunction="displayMantant"							   
									   width="80" textAlign="right" showDataTips="true"/>
				</component:columns>
			</component:DataGridEx>
		</mx:HBox>
 
		<mx:HBox width="100%"
				 height="30" paddingRight="10"  paddingBottom="0" paddingTop="0" horizontalAlign="right">
			<mx:Label text="Total:"
					  width="57">
			</mx:Label>
			<mx:TextInput enabled="false"
						  styleName="CMTotal"
						  width="120" id="totalMedical">
			</mx:TextInput>
		</mx:HBox>
	</mx:VBox>
</mx:Module>
DataGridEx.as
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 package com.grid
  {
 import flash.display.Sprite;
 
 import mx.collections.ArrayCollection;
 import mx.controls.DataGrid;
 
 public class DataGridEx extends DataGrid
  {
   public var rowBackgroundColorFunction:Function;
   public function DataGridEx()
    {
      super();
    }
 
  override protected function drawRowBackground(s:Sprite, rowIndex:int,
      y:Number, height:Number,color:uint, dataIndex:int):void
        {
        if( rowBackgroundColorFunction!=null ){
        var item:Object = (dataProvider as ArrayCollection).getItemAt(dataIndex);
        if(item.etat=="ERROR" )
        color = rowBackgroundColorFunction(item);
        }
            super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);
    }
 
  }
 
}
Cordialement.
sinfos est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/05/2011, 13h20   #2
Membre à l'essai
 
Inscription : octobre 2007
Messages : 79
Détails du profil
Informations forums :
Inscription : octobre 2007
Messages : 79
Points : 22
Points : 22
le problème n'est pas dans le ArrayCollection c'est probleme au niveaux de dataIndex dans la methode surcharger du datagride ou il faut ajouter un traitement la dessous:
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
override protected function drawRowBackground(s:Sprite, rowIndex:int,
      y:Number, height:Number,color:uint, dataIndex:int):void
        {
       if( rowBackgroundColorFunction!=null ){
       	if(dataIndex<(dataProvider as ArrayCollection).length)
       	{
        var item:Object = (dataProvider as ArrayCollection).getItemAt(dataIndex);
        if(item.etat=="ERROR" )
        color = rowBackgroundColorFunction(item);
        }
        }
            super.drawRowBackground(s,rowIndex,y,height,color,dataIndex);
    }
Cordialement
sinfos est déconnecté   Envoyer un message privé Réponse avec citation 10
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 07h53.


 
 
 
 
Partenaires

Hébergement Web